Python list of dictionary

閱讀時間約 2 分鐘

簡單介紹 如何在list中放入dictionary

candidates=[
{"Name":"Lai","Party":"DPP","Born":"New Taipei" },
{"Name":"Hou","Party":"KMT","Born":"Chiayi"},
{"Name":"Ko","Party":"TPP","Born":"Hsinchu"},
{"Name":"Guo","Party":None,"Born":"New Taipei"}
]
for i in candidates:
print(i["Name"])

terminal 印出
Lai
Hou
Ko
Guo​
--------------------------------------------------------
candidates=[
{"Name":"Lai","Party":"DPP","Born":"New Taipei" },
{"Name":"Hou","Party":"KMT","Born":"Chiayi"},
{"Name":"Ko","Party":"TPP","Born":"Hsinchu"},
{"Name":"Guo","Party":None,"Born":"New Taipei"}
]
for i in candidates:
print(i["Name"],i["Party"],i["Born"],sep=", ")

terminal 印出
Lai, DPP, New Taipei
Hou, KMT, Chiayi
Ko, TPP, Hsinchu
Guo, None, New Taipei




avatar-img
3會員
26內容數
寫程式的筆記,把一些自學寫過的程式放上來
留言0
查看全部
avatar-img
發表第一個留言支持創作者!
你可能也想看
從 Google News 追蹤更多 vocus 的最新精選內容