iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 9
0
Data Technology

Python學習筆記系列 第 9

[Day9 ] Dictionary字典

Dictionary(dict)又稱關聯記憶體,dictionary是由key來當索引,它可以是任何不可變的型態,字串和數字都可以當作key。

Dict是一組無序的鍵值對集合(key : value),其中key必須是獨一無二的。而mappings則是將物件儲存在key裡的集合,Dict主要操作為藉由鍵來儲存一個值,並可用該鍵來取得該值。
那現在來開示範一下Dictionary要如何使用

https://ithelp.ithome.com.tw/upload/images/20171212/20107290ZWZv6kuJcl.png

https://ithelp.ithome.com.tw/upload/images/20171212/20107290Lebus0tbI9.png


Python有內鍵"加"和"減"的函數,可以用+=和-+表示以上的statement,請詳下圖

https://ithelp.ithome.com.tw/upload/images/20171212/20107290qJyr5p9CyJ.png


我們也可以先創建一個空的dictionary,然後再指派key值

https://ithelp.ithome.com.tw/upload/images/20171212/20107290jt6hSPK3Zc.png


Dictionary的巢狀結構

https://ithelp.ithome.com.tw/upload/images/20171212/20107290oYnLF5hNpo.png

https://ithelp.ithome.com.tw/upload/images/20171212/20107290IyvkTTo8S6.png

資料來源: Go from zero to hero in Python


上一篇
[Day 8] Lists 串列
下一篇
[Day10] Tuples 元組
系列文
Python學習筆記14
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言