1. 程式人生 > >python刪除元素

python刪除元素

name = ["wangfei","weiwei","baba","mama","yeye"]
name.remove("yeye")
print(name)

 name.remove("yeye")   #只需知道元素,就可以刪除

name = ["wangfei","weiwei","baba","mama","yeye"]
del name[1]
print(name)

del name[1]    # 知道位置就可以刪除

name = ["wangfei","weiwei","baba","mama","yeye"]
del name

 del name   #直接給列表刪除了

name = ["wangfei","weiwei","baba","mama","yeye"]
name.pop()
print(name)

 name.pop()  #直接刪除末尾

name = ["wangfei","weiwei","baba","mama","yeye"]
name.pop(2)
print(name)

name.pop(2)   #按位置刪除