#張佑維拷貝自 201單元
"""for x in 'Takming': #迴圈逐字元印出
print("字母: %s" % x)三引號框起註解
"""
fruits = ['台積電', '鴻海', '聯發科'] #台灣市場價值最高的三公司
for x in fruits: #
print ("公司: %s" % x)
print(fruits)
fruits.append("中華電")
print("使用append")
print(fruits)
fruits.clear()
print("使用clear")
print(fruits)
fruits = ['台積電', '鴻海', '聯發科', '中華電']
chicken = fruits.copy()
#和 chicken = fruits 有何不同?
print(chicken)
fruits.append("中華電")
print(fruits.count("中華電"))
print(fruits.count("台積電"))
for x in fruits:
print(x)
if x == "中華電": #判斷式是否banana
print('I hate 中華電.')
if x == "聯發科": #判斷式是否cherry
print('I like cherry.')
if x == "鴻海": #判斷式是否apple
print('You are my sweet apple.')
#從中我體會到只要我有耐心與興趣並堅持到最後,我也可以當一個專業的程式開發人員
張佑維利用w3school學習HTML,CSS,Borders 德 明 張 佑 維 Html上的物件,稱為元素body, p=paragraph, div=division, iframe框架 教學影片138 用w3schools編輯網頁 使用專業程式碼編輯器IDE整合開發環境 整合開發環境(Integrated Development Environment, IDE)。width霓度,height高度,src=source來源。 JAVA變數 String-字串- text, such as "Hello". String values are surrounded by double quotes int-整數- integers (whole numbers), without decimals, such as 123 or -123 F1oat-浮點數,買數- floating point numbers, with decimals, such as 19.99 or-19. 99 char-宇兀-single characters, such as'a'or'B'. Char values are surrounded by singlequotes$1i>boolean-邏輯stores values with two states: true or false
w3scholls截圖 w3scholls練習程式碼 #字典 keys:values, 張佑維 #w3schools原來 字串:字串,改成 整數:字串 a = { #市場價值最大的五家公司 2330: "台積電", 2317: "鴻海", 2454: "聯發科", 2412: "中華電", 6505: "台塑化" } print(a) print(a[6505]) print(a.get(2330))#功能同 a[2330] print(a.keys()) #keys()方法列出key搜尋鍵 print(a.values()) #keys()方法列出values值 b = a.copy() print("列出b " + str(b)) print(b[2317]) print(b.clear()) a.update({2308: "台達電"}) print(a.values()) print("用迴圈列出字典a的所有值") for t in a: print(a[t]) 字典方法Dictionary Methods Python has a set of built-in methods that you can use on dictionaries. Method Description clear() Removes all the elements from the dictionary copy() Returns a copy of the dictionary fromkeys() Returns a dictionary with the specified keys and value get() Returns the value of the specified key items() Returns a list containing a tuple for each key value pair keys() Returns a list containing the dictionary's keys pop() ...
留言
張貼留言