Python之列表应用

来源:互联网 发布:react set state 源码 编辑:程序博客网 时间:2024/05/16 12:47

列表元素的追加、排序、删除与查询

storage = ["note","pencil","pen","eraser"]

print("I have ",len(storage),"items")
print("This items are:")
for item in storage:
print("item-->",item)
print("\nI also have to buy a ruler")
storage.append("ruler")
print("Now I have :",storage)
print("I want to sort")
storage.sort()
print("After sort :",storage)
print("The first item I have is:",storage[0])
olditem = storage[0]
del storage[0]
print("I lost the ",olditem)
print("After delete:",storage)
原创粉丝点击