標題:
串列 (二)
[打印本頁]
作者:
tonyh
時間:
2018-7-14 09:40
標題:
串列 (二)
假設有一串列其內容如下:
list=[12,-3,-50,32,25,11]
試以sort()、reverse()、pop()、append()、insert()等函式,完成如下操作:
[attach]4450[/attach]
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)
複製代碼
作者:
曲書辰
時間:
2018-7-14 09:56
本帖最後由 曲書辰 於 2018-7-14 09:57 編輯
list=["A","B","C","D","e","G","F"]
print("排序前",list)
list.sort();
print("排序後",list)
list.reverse();
print("排序後",list)
print("排序後",list)
print("元素數量",len(list))
list.pop()
print("pop掉一元素",list)
list.append(-20)
print("append一元素",list)
list.insert(4,0)
print("insert一元素",list)
複製代碼
作者:
古蕾娜
時間:
2018-7-14 09:56
list=[42,95,-69,7,-22]
print("Before sort: ",list)
list.sort()
print("After sort(ascending): ",list)
list.reverse()
print("Before sort(descending): ",list)
print("Number of values:",len(list))
list.pop()
print("pop0 away one value",list)
list.append(-20)
print("append away one value",list)
list.insert(4,0)
print("insert one value",list)
複製代碼
作者:
古昇暘
時間:
2018-7-14 10:00
list=[12,-3,-50,32,25,11]
print("before list: ",list)
list.sort();
print("after list(ascending): ",list)
list.reverse();
print("after list(ascending): ",list)
print("ammount: ",len(list))
list.pop()
print("pop one ammount: ",list)
list.append(-20);
print("append one ammount: ",list)
list.insert(4,0);
print(*"isert one ammount: ",list)
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2