代码点读机 / Python / pop

pop Python · 通用方法

从列表末尾或字典指定键取走元素并返回;原容器会少一个。

怎么用

列表.pop() 或 字典.pop(键, 默认值)

小例子

a = [1, 2, 3]
print(a.pop())
print(a)

运行结果

3
[1, 2]

官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条