劉任昌Python字典Dictionaries

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.
MethodDescription
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

留言

  1. https://cpc920508123.blogspot.com/2023/03/pythondictionary.html

    回覆刪除
  2. 作者已經移除這則留言。

    回覆刪除
  3. https://d11150115.blogspot.com/2023/03/dictionary-methods-python-has-set-of.html

    回覆刪除
  4. 作者已經移除這則留言。

    回覆刪除
  5. https://liiuzhewei.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  6. https://rtytrdtfg.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  7. https://d10917257.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  8. https://cindy-javascript.blogspot.com/2023/03/blog-post.html

    回覆刪除
  9. https://alien1213.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  10. https://enchenghu0905.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  11. https://tgyhjikolujik2554.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  12. https://html-css-javascript-yaoto.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  13. https://jasperyang.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  14. https://changmasaxciksdj.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  15. https://html-css-zz-javascript-java.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  16. https://d11150114.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  17. https://643gjeytfru4312.blogspot.com/2023/03/python.html

    回覆刪除
  18. https://iuytjhg5261.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  19. https://trequiem.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  20. https://wutimothy.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  21. https://d11150118.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  22. https://hhhaann.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  23. https://d11150108.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  24. https://efnmklfnmk.blogspot.com/2023/03/w3scholls-w3scholls-keysvalues.html

    回覆刪除
  25. https://d11150116.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  26. https://chenyouzheng0329.blogspot.com/2023/03/pythondictionaries.html

    回覆刪除
  27. https://www.blogger.com/blog/post/edit/7946957304410713297/700350125472813664

    回覆刪除

張貼留言

這個網誌中的熱門文章

劉任昌對照Python與JavaScript指令

劉任昌Python集合set清單list元組tuple字典dictionary

劉任昌python, input, str, float