侯又誠python陣列array

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

教學影片

230

234

235

影片

留言

這個網誌中的熱門文章

侯又誠期中考作業

侯又誠風險管理制度與實務18屆