您的位置:首页 > 编程语言 > Python开发

python中list(元组)删除元素的方法

2014-05-08 15:36 811 查看
Removing
elements from lists


点击打开链接

1.  .pop()

n = [1, 3, 5]
n.pop(1)
# Returns 3 (the item at index 1)
print n
# prints [1, 5]

2.  .remove()
n.remove(1)
# Removes 1 from the list,
# NOT the item at index 1
print n
# prints [3, 5]

3.  del()
del(n[1])
# Doesn't return anything
print n
# prints [1, 5]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: