葉可棠python集合set元組tuple清單或串列list迴圈輸出str,int

w3schools截圖

w3schools程式碼

#葉可棠 集合{},清單[],元組(),字典{key:value}
s = {"台積電", "鴻海", "聯發科", "中華電", "台塑化"}
t = ("台積電", "鴻海", "聯發科", "中華電", "台塑化")
list = ["台積電", "鴻海", "聯發科"]
d = {2330:"台積電", 2317:"鴻海", 2454:"聯發科"}
print("s型態" + str(type(s)))
print("t型態" + str(type(t)))
print("d型態" + str(type(d)))
print("t型態" + str(type(list)))
#字串與字串+
i = 0
for a in t:  
      i = i + 1
      print("台灣市場價格第" + str(i) + "大公司是")
      print("   " + a)
print("聯發科的位置" + str(t.index("聯發科")))
'''python大區塊的註解,前後用三個引號 str 轉成字串 int 轉成數字'''

w3schools元組tuples的方法

Python has two built-in methods that you can use on tuples.

MethodDescription
count()Returns the number of times a specified value occurs in a tuple
index()Searches the tuple for a specified value and returns the position of where it was found

w3schools清單或串接lists的方法

教學影片

影片229

留言

張貼留言

這個網誌中的熱門文章

葉可棠python字典

葉可棠期中考VS Code編輯Python