返回列表 發帖

串列 (二)

假設有一串列其內容如下:
list=[12,-3,-50,32,25,11]

試以sort()、reverse()、len()、pop()、append()、insert()等函式,完成如下操作:

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort()
  4. print("排序後(遞增):",list)
  5. list.reverse()
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一個元素",list)
  10. list.append(-20)
  11. print("append一個元素:",list)
  12. list.insert(4,0)
  13. print("insert一個元素:",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort()
  4. print("排序後(遞增):",list)
  5. list.reverse()
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素:",list)
  10. list.append(-20)
  11. print("append一元素:",list)
  12. list.insert(4,0)
  13. print("insert一元素:",list)
複製代碼
Allen

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",list)
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20);
  11. print("append一元素",list)
  12. list.insert(4,0);
  13. print("insert一元素",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前: ",list)
  3. list.sort()
  4. print("排序後(遞增): ",list)
  5. list.reverse()
  6. print("排序後(遞減): ",list)
  7. print("元素數量: ",list)
  8. list.pop()
  9. print("pop掉一元素 ",list)
  10. list.append(-20)
  11. print("append一元素 ",list)
  12. list.insert(4,0)
  13. print("insert一元素 ",list)
複製代碼
Ivy

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前: ",list)
  3. list.sort( );
  4. print("排序後(遞增): ",list)
  5. list.reverse();
  6. print("排序後(遞減):" ,list)
  7. print("元素數量: ",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sport();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞增):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一個元素:",list)
  10. list.append(-20)
  11. print("append一元素:",list)
  12. list.insert(4,0)
  13. print("insert一元素:",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort()
  4. print("排序後(遞增):",list)
  5. list.reverse()
  6. print("排序後(遞減):",list)
  7. print("元素數量",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
  14. list.remove(25)
  15. print(list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort()";
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert.(4,0)
  13. print("insert一元素,list)
複製代碼

TOP

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.append(-20)
print("append掉一個元素")
list.insert(4,0)
print("insert掉一個元素")

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前: ",list)
  3. list.sort( );
  4. print("排序後(遞增): ",list)
  5. list.reverse();
  6. print("排序後(遞減):" ,list)
  7. print("元素數量: ",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert一元素",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量",len(list))   
  8. list.pop();
  9. print("pop掉一個元素:",list)
  10. list.append(-20);
  11. print("append一元素:",list)
  12. list.insert(4,0);
  13. print("insert一元素:",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素",list)
  10. list.append(-20)
  11. print("append一元素",list)
  12. list.insert(4,0)
  13. print("insert-元素",list)
複製代碼

TOP

  1. list=[12,-3,-50,32,25,11]
  2. print("排序前:",list)
  3. list.sort();
  4. print("排序後(遞增):",list)
  5. list.reverse();
  6. print("排序後(遞減):",list)
  7. print("元素數量:",len(list))
  8. list.pop()
  9. print("pop掉一元素:",list)
  10. list.append(-20)
  11. print("排序後(遞增):",list)
  12. list.insert(4,0)
  13. print("排序後(遞增):",list)
複製代碼

TOP

返回列表