本帖最後由 陳牧謙 於 2022-8-19 13:42 編輯
- list=["忠","孝","仁","愛",]
- print("原始list",list)
- print("--新增--")
- list.append("apple")
- print("append:",list)
- list.insert(1,"banana")
- print("insert:",list)
- print("--刪除--")
- list.pop()
- print("pop:",list)
- list.remove("banana")
- print("remove:",list)
- list2=[1,2,3,100,99,50,0,12,-3,-50,32,25,11]
- print("--排序--")
- list2.sort()
- print("sort由小到大:",list2)
- list2.sort(reverse=True)
- print("sort由大到小:",list2)
- print("--反向--")
- list2.reverse()
- print("list2 reverse:",list2)
- list.reverse()
- print("list reverse:",list)
- print("--長度--")
- print("list的長度",len(list))
- print("list2的長度",len(list2))
複製代碼 |