python中pop什么意思-Python教程

资源魔 45 0

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

咱们将列表a的地位1的元素移除了

将列表b的地位0的元素移除了并赋值给变量b1

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

输入后果:

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

相干保举:《Python教程》

以上就是python中pop甚么意义的具体内容,更多请存眷资源魔其它相干文章!

标签: Python pop python教程 python编程 python使用问题

抱歉,评论功能暂时关闭!