假設有一串列其內容如下:
list=[12,-3,-50,32,25,11]
試以sort()、reverse()、pop()、append()、insert()等函式,完成如下操作:
- list=[12,-3,-50,32,25,11]
- print("排序前:",list)
- list.sort();
- print("排序後(遞增):",list)
- list.reverse();
- print("排序後(遞減):",list)
- print("元素數量:",len(list))
- list.pop()
- print("pop掉一元素",list)
- list.append(-20)
- print("append一元素",list)
- list.insert(4,0)
- print("insert一元素",list)
複製代碼 |