- # -*- coding: utf-8 -*-
- """
- Spyder Editor
- This is a temporary script file.
- """
- list1 = [2,1,"忠","孝","仁","愛","信","義","和","平"]
- print("原始list1",list1)
- #list新增
- list1.append(-20) #最後+
- print("append一元素",list1)
- list1.insert(1,5) #指定+
- print("insert一元素",list1)
- #list清除
- list1.pop() #最後-
- print("pop一元素",list1)
- list1.remove(5) #指定-
- print("remove一元素",list1)
- list2=[12,-3,-50,32,25,11]
- print("原始list2:",list2)
- list2.sort(reverse=1)
- print("排序list2:",list2)
複製代碼 |