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

查看所有标签

HTTP

HTTP

David Gourley、Brian Totty、Marjorie Sayer、Anshu Aggarwal、Sailu Reddy / O'Reilly Media / 2002-10-7 / USD 54.99

Product Description Web technology has become the foundation for all sorts of critical networked applications and far-reaching methods of data exchange, and beneath it all is a fundamental protocol......一起来看看 《HTTP》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具