陳瑀晞python陣列array

w3schools截圖

w3schools程式碼

#陳瑀晞陣列
#for x in 'Takming gold':     # 第一个實例
#   print("當前字母: %s" % x)
fruits = ['台積電', '鴻海', '聯發科']
for x in fruits:        # 第二个實例
   print ("最大公司水果: %s" % x)
print ("練習陣列的11個內建方法")
fruits.append("中華電") #append加元素
fruits.clear()
fruits = ['台積電', '鴻海', '聯發科', '中華電']
print(fruits)
pig = fruits.copy()
print("輸出pig=fruits.copy()結果" + str(pig))
cat = fruits
print("輸出cat=fruits的結果"+str(cat))
fruits.extend(fruits) #extend尾巴+陣列, append加元素
print("extend的 "+str(fruits))
print("copy  的 "+str(pig))
print("  =   的 "+str(cat))
print(fruits.count("台積電"))
fruits.insert(1,"富邦金")
print(fruits)
print(fruits.index("富邦金"))
fruits.reverse()
print(fruits)
fruits.sort()
print(fruits)
fruits.remove("富邦金") #拿走富邦金
print(fruits)
fruits.pop(2) #拿走012的2
print(fruits)
#只要我認真學習,應該也可以當一個專業的程式開發人員吧

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

影片教學

影片

留言

張貼留言

這個網誌中的熱門文章

產業分析作業

陳瑀晞python運算CSV輸出TKINTER投資風險與報酬Markowitz

馬可維茲風險平均數平面