好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python中pop什么意思

python中pop()将列表指定位置的元素移除,同时可以将移除的元素赋值给某个变量,不填写位置参数则默认删除最后一位

pop()根据键将字典中指定的键值对删除,同时可以将删除的值赋值给变量

举个例子:

 a = ["hello", "world", "dlrb"]
 b = ["hello", "world", "dlrb"]
 a.pop(1)
 b1 = b.pop(0)
 print(a)
 print(b1) 

输出结果:

['hello', 'dlrb']
hello 

 b = {
    "name":"dlrb",
     "age":25,
     "height":168
 }
 b1 = b.pop("age")
 print(b)
 print(b1) 

输出结果:

{'name': 'dlrb', 'height': 168}
25 

相关推荐:《Python教程》

以上就是python中pop什么意思的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于python中pop什么意思的详细内容...

  阅读:52次