python pop

python pop函数

字典pop

Python 字典 pop() 方法删除字典给定键 key 及对应的值,返回值为被删除的值。key 值必须给出。 否则,返回 default 值。

dict.pop(key)

test = {'name': 'heng', 'age': 30}
result = test.pop('name')
print(result)
heng

列表pop

移除列表中的一个元素(默认最后一个元素),并且返回该元素的值

list.pop(index=-1)

test = ["heng1", "heng2", "heng3"]
result = test.pop()
print(result)
print(test)
result = test.pop(0)
print(result)
print(test)
heng3
['heng1', 'heng2']
heng1
['heng2']
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值