標題:
串列 (二)
[打印本頁]
作者:
tonyh
時間:
2020-7-28 10:33
標題:
串列 (二)
假設有一串列其內容如下:
list=[12,-3,-50,32,25,11]
試以sort()、reverse()、len()、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)
複製代碼
作者:
林婕瀅
時間:
2020-7-28 10:42
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)
複製代碼
作者:
黃家穎
時間:
2020-7-28 10:42
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)
複製代碼
作者:
黃明晧
時間:
2020-7-28 10:45
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)
複製代碼
作者:
黃明曄
時間:
2020-7-28 10:45
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)
複製代碼
作者:
林睿謙
時間:
2020-7-28 10:48
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
複製代碼
作者:
陳紀希
時間:
2020-7-28 10:49
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)
複製代碼
作者:
王法棣
時間:
2020-7-28 10:49
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)
複製代碼
作者:
戴睿呈
時間:
2020-7-28 10:50
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)
複製代碼
作者:
林家代
時間:
2020-7-28 10:50
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)
複製代碼
作者:
黃瀚永
時間:
2020-7-28 10:51
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)
複製代碼
作者:
楊子瑩
時間:
2020-7-28 10:52
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)
複製代碼
作者:
李睿騏
時間:
2020-7-28 10:53
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)
複製代碼
作者:
蔡鈞峰
時間:
2020-7-28 10:53
o=[12,-3,-50,32,25,11]
print("排序前",o)
o.sort();
print("排序後(遞增)",o)
o.reverse();
print("排序後(遞減)",o)
print("元素數量",len(o))
o.pop()
print("pop掉一元素",o)
o.append(-20)
print("append一元素",o)
o.insert(4,0)
print("insert一元素",o)
複製代碼
作者:
陳星翰
時間:
2020-7-28 10:55
list=[12,-3,-50,32,25,11]
print("list:", list)
list.sort();
print("numbers(least to greatest):",list)
list.reverse();
print("numbers(greatest to smallest):",list)
print("number of numbers:",len (list))
list.pop()
print("popped smalest number",list)
list.append(-20)
print("appended a number",list)
list.insert(4,0)
print("inserted numbers",list)
複製代碼
作者:
楊書華
時間:
2020-7-28 10:57
list=[2004,6,22,2005,2,5]
print("Unsorted: ", list)
list.sort()
print("From least to Greatest:", list)
list.reverse()
print("From Greatest to Least: ", list)
print("Numer of Elements: ", len(list))
list. pop(5)
print("After Deleting one Element: ", list)
list. pop(2)
print("After Deleting two Elements: ", list)
list. append(9)
list.sort()
print("After Adding a new Element: ", list)
list. append(23)
list.sort()
print("After Adding two new Elements: ", list)
list. pop(1)
print("After Deleting one Element: ", list)
list. pop(0)
print("After Deleting two Elements: ", list)
list.insert(0,3)
print("After Adding a new Element: ", list)
list.insert(1,4)
list.sort()
print("After Adding a new Element: ", list)
複製代碼
作者:
蔡旭隆
時間:
2020-7-28 10:59
k=[12,-3,-50,32,25,11]
print("排序前:",k)
k.sort();
print("排序後(遞增):",k)
k.reverse();
print("排序後(遞減):",k)
print("元素數量:",len(k))
k.pop()
print("pop掉一元素",k)
k.append(-20)
print("append一元素",k)
k.insert(4,0)
print("一元素",k)
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2