其他分享
首页 > 其他分享> > 删除操作

删除操作

作者:互联网

movieName = ["加勒比海盗", "骇客帝国", "滴一滴写", "指环王", "霍比特人", "速度与激情"]

print("----------删除之前--------------")
for i in movieName:
    print(i)
    
#del 根据下标删除
print("----------del删除之后---------------")
del movieName[2]
for i in movieName:
    print(i)
    
# pop删除最后一个元素
print("---------pop删除之后-----------------")
movieName.pop()
print(movieName)
for i in movieName:
    print(i)
    
# 根据元素的值进行删除
print("---------remove删除之后--------------")
movieName.remove("加勒比海盗")
for i in movieName:
    print(i)

 

标签:删除,pop,del,remove,print,操作,movieName
来源: https://www.cnblogs.com/SP-0306/p/10900602.html