Python List Pop

Syntax

Following is the syntax for pop() method −

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

Parameters

  • obj -- This is an optional parameter, index of the object to be removed from the list.

Return Value

This method returns the removed object from the list.

Example

The following example shows the usage of pop() method.

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc'];

print "A List : ", aList.pop()
print "B List : ", aList.pop(2)

When we run above program, it produces following result −

A List :  abc
B List :  zara
发布了0 篇原创文章 · 获赞 34 · 访问量 44万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览