Python中的pop()函数

描述

pop() 函数用于随机移除列表中的一个元素(默认最后一个元素),并且返回该元素的值。

返回值

从列表中移除的元素对象。

实例

fruits = {'apple','banana','cherry'}
x = fruits.pop()
print(x)
print(fruits)

结果

banana
{'cherry', 'apple'}

你可能感兴趣的:(python)