標題:
串列 (二)
[打印本頁]
作者:
陳品肇
時間:
2020-2-2 09:02
標題:
串列 (二)
假設有一串列其內容如下:
list=[12,-3,-50,32,25,11]
試以sort()、reverse()、len()、pop()、append()、insert()等函式,完成如下操作:
[attach]8362[/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)
複製代碼
作者:
陳頡鴻
時間:
2020-2-2 11:15
list1=[12,-3,-50,32,25,11]
print("排序前:",list)
list1.sort();
print("排序後(遞增):",list1)
list.reverse();
print("排序後(遞減):",list1)
print("元素數量:",len(list1))
list1.pop()
print("pop掉一元素",list1)
list.append(-20)
print("append一元素",list1)
list1.insert(4,0)
print("insert一元素",list1)
複製代碼
作者:
陳沛頤
時間:
2020-2-2 11:16
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-2-2 11:17
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-2-2 11:17
[code][/code]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)# -*- coding: utf-8 -*-
作者:
黃紹綸
時間:
2020-2-2 11:19
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-2-2 11:20
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-2-2 11:20
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-2-2 11:22
list=[11,-4,-25,50,1,15]
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)
list.clear()
print(list)
複製代碼
作者:
曾顗文
時間:
2020-2-2 11:22
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-2-2 11:22
a=[1,2,3,4,5,6,"a","b","c","d"]
print(type(a[4]))
print(type(a[6]))
print(len(a))
a.append("e")
print(a)
a.insert(11,"f")
print(a)
a.pop(0)
print(a)
a.remove("f")
print(a)
b=[5,0,1,4,6,1]
b.sort()
print(b)
b.reverse()
print(b)
複製代碼
作者:
許雅棟
時間:
2020-2-2 11:23
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-2-2 11:24
list=[12,-3,-50,32,25,11]
print("前:",list)
list.sort();
print("遞增:",list)
list.reverse();
print("遞減:",list)
print("元素數量:",len(list))
list.pop()
print("刪除一元素",list)
list.append(-20)
print("增加一元素",list)#加到最後
list.insert(4,0)
print("加入一元素",list)#加到指定位子
複製代碼
作者:
潘堉恩
時間:
2020-2-2 11:24
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-2-2 11:26
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-2-2 11:29
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-2-2 13:43
a=[]
for i in range(1,100,2):
a.insert(0,i)
for b in a:
print(b)
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2