劉任昌python陣列array

w3schools陣列截圖

w3schools陣列程式碼

#劉任昌w3schools練習
#for x in 'Takming gold': #迴圈逐字字元
#   print("字母: %s" % x)
fruits = ['台積電', '鴻海', '聯發科']
for x in fruits:      # 迴圈印出元素
   print ("當前公司: %s"% x)
print ("append") #append在末尾增加
fruits.append("中華電") #append接元素
print(fruits)
print("移除所有元素clear")
fruits.clear() #Removes all the elements from the list
print(fruits)
fruits = ['台積電', '鴻海', '聯發科',"中華電"]
print(fruits)
pig = fruits.copy()
print("輸出pig用copy方法" + str(pig))
print("使用copy和直接賦予值 pig = fruits有何不同? ")
dog = fruits
print("輸出dog直接=" + str(dog))
print("fruits.extend(pig)")
fruits.extend(pig) #extend接陣列或清單
print(fruits)
fruits.extend(['台塑化','台達電','富邦金'])
print(fruits)
#print("幾個台積電? " + str(fruits.count("台積電)))
print(fruits.index("富邦金"))
fruits.insert(10,"國泰金")
print(fruits)
print(fruits.index("富邦金"))
print("fruits元素個數" + str(len(fruits)))
fruits.pop(4)
print(fruits)
fruits.reverse() #反序排列
print(fruits)
fruits.sort() #排序按照字碼
print(fruits)
#體會到只要我有耐心與興趣,我也可以當一個專業的程式開發人員

w3schools陣列方法Array Methods

陣列方法Array Methods Python語言有一組內建的方法(built-in methods)
方法Method說明Description
append()Adds an element at the end of the list
clear() Removes all the elements from the list
copy() Returns a copy of the list
count() Returns the number of elements with the specified value
extend() Add the elements of a list (or any iterable), to the end of the current list
index() Returns the index of the first element with the specified value
insert()Adds an element at the specified position
pop() Removes the element at the specified position
remove()Removes the first item with the specified value
reverse()Reverses the order of the list
sort()排序Sorts the list

w3schools轉寫模式拷貝方法表格

Array Methods

Python has a set of built-in methods that you can use on lists/arrays.

MethodDescription
append()Adds an element at the end of the list
clear()Removes all the elements from the list
copy()Returns a copy of the list
count()Returns the number of elements with the specified value
extend()Add the elements of a list (or any iterable), to the end of the current list
index()Returns the index of the first element with the specified value
insert()Adds an element at the specified position
pop()Removes the element at the specified position
remove()Removes the first item with the specified value
reverse()Reverses the order of the list
sort()Sorts the list

教學影片

230

234

235

留言

  1. https://gary20010101.blogspot.com/2023/04/blog-post.html

    回覆刪除
  2. https://youningningjava.blogspot.com/2023/04/pythoonarray.html

    回覆刪除
  3. https://gracetakming.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  4. https://elainehaung0812.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  5. https://lilyhuangyuanntakming.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  6. https://java-css-javascript-html.blogspot.com/2023/04/pythonarray_9.html

    回覆刪除
  7. https://leitrezesig.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  8. https://takmingyiching.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  9. https://sherryd11117110.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  10. https://takmingd11117123.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  11. https://ericlian-pc.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  12. https://hosidesu.blogspot.com/2023/04/titlearray.html

    回覆刪除
  13. https://chen-ping0330.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  14. https://sophie0930307.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  15. https://mandytakming.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  16. https://zoetakming.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  17. https://yvonned11117232.blogspot.com/2023/04/pytonarray.html

    回覆刪除
  18. https://xiao920727.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  19. https://sususu0123.blogspot.com/2023/04/h1background-color-purple-color-white.html

    回覆刪除
  20. https://sarahyu-programming.blogspot.com/2023/04/pythonarray.html

    回覆刪除
  21. https://d11117235catian.blogspot.com/2023/04/pythoyarray.html

    回覆刪除
  22. https://cathyleerou.blogspot.com/2023/04/h1background-color-purple-color-white.html

    回覆刪除
  23. https://jennysuwanting.blogspot.com/2023/05/pythonarray.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

劉任昌Bro Code貪吃蛇python snake game

劉任昌HTML金一乙

劉任昌tkinter視窗函式庫Entry工具widget