首页 > 文章列表 > Python pop是什么

Python pop是什么

Python pop
311 2022-08-07

1、概念

是按索引号来删除列表中对应的元素,并返回该元素。

2、语法

list.pop(obj=list[-1])

3、参数

Obj,可选参数,要移除列表元素的对象。

4、返回值

该方法返回从列表中移除的元素对象。

5、实例

>>> listA = ['a', 'b', 'c','a', 'b', 'c', 'a', 'b','c']
>>> w = listA.pop(3)
>>> w
'a'
>>> print(listA)
['a', 'b', 'c', 'b', 'c', 'a', 'b', 'c']

(推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)