趙婧伶python陣列array

w3schools截圖

w3schools程式碼

#趙婧伶陣列
#for letter in 'Takming':     # 第一个实例
   #print("當前字母: %s" % letter)

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陣列方法

數組方法

Python 有一組可用於列表/數組的內置方法。

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

教學影片

影片

留言

這個網誌中的熱門文章

趙婧伶風險管理制度與實務charCodeAt()

趙婧伶風險管理制度與實務18屆