Python List pop()方法

Python 教程 · 2019-02-02 22:28:10

描述

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

语法

pop()方法语法:

list.pop([index=-1])

参数

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

返回值

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

实例

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

实例

#!/usr/bin/python3 #coding=utf-8 list1 = ['Google', 'Codercto', 'Taobao'] list_pop=list1.pop(1) print "删除的项为 :", list_pop print "列表现在为 : ", list1

以上实例输出结果如下:

删除的项为 : Codercto
列表现在为 :  ['Google', 'Taobao']

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

查看所有标签

Think Python

Think Python

Allen B. Downey / O'Reilly Media / 2012-8-23 / GBP 29.99

Think Python is an introduction to Python programming for students with no programming experience. It starts with the most basic concepts of programming, and is carefully designed to define all terms ......一起来看看 《Think Python》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具