Python3 List pop()方法

Python 3 教程 · 2019-02-06 13:29:47

描述

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

语法

pop()方法语法:

list.pop([index=-1])

参数

  • index -- 可选参数,要移除列表元素的索引值,不能超过列表总长度,默认为 index=-1,删除最后一个列表值。

返回值

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

实例

以下实例展示了 pop()函数的使用方法:

#!/usr/bin/python3

list1 = ['Google', 'Codercto', 'Taobao']
list1.pop()
print ("列表现在为 : ", list1)
list1.pop(1)
print ("列表现在为 : ", list1)

以上实例输出结果如下:

列表现在为 :  ['Google', 'Codercto']
列表现在为 :  ['Google']

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Paradigms of Artificial Intelligence Programming

Paradigms of Artificial Intelligence Programming

Peter Norvig / Morgan Kaufmann / 1991-10-01 / USD 77.95

Paradigms of AI Programming is the first text to teach advanced Common Lisp techniques in the context of building major AI systems. By reconstructing authentic, complex AI programs using state-of-the-......一起来看看 《Paradigms of Artificial Intelligence Programming》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具