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() | Removes the element with the specified key |
| popitem() | Removes the last inserted key-value pair |
| setdefault() | Returns the value of the specified key. If the key does not exist: insert the key, with the specified value |
| update() | Updates the dictionary with the specified key-value pairs |
| values() | Returns a list of all the values in the dictionary
|
教學影片216
教學影片217
教學影片218
https://cpc920508123.blogspot.com/2023/03/pythondictionary.html
回覆刪除作者已經移除這則留言。
回覆刪除https://d11150115.blogspot.com/2023/03/dictionary-methods-python-has-set-of.html
回覆刪除作者已經移除這則留言。
回覆刪除https://liiuzhewei.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://rtytrdtfg.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://d10917257.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://cindy-javascript.blogspot.com/2023/03/blog-post.html
回覆刪除https://alien1213.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://enchenghu0905.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://tgyhjikolujik2554.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://html-css-javascript-yaoto.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://jasperyang.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://changmasaxciksdj.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://html-css-zz-javascript-java.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://d11150114.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://643gjeytfru4312.blogspot.com/2023/03/python.html
回覆刪除https://iuytjhg5261.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://trequiem.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://wutimothy.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://d11150118.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://hhhaann.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://d11150108.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://efnmklfnmk.blogspot.com/2023/03/w3scholls-w3scholls-keysvalues.html
回覆刪除https://d11150116.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://chenyouzheng0329.blogspot.com/2023/03/pythondictionaries.html
回覆刪除https://www.blogger.com/blog/post/edit/7946957304410713297/700350125472813664
回覆刪除