python dictionary 簡單用法
candidates={
"Lai":"DPP",
"Hou":"KMT",
"Ko":"TPP",
"Guo": "GT",
}
print(candidates["Lai"])
print(candidates["Hou"])
print(candidates["Ko"])
print(candidates["Guo"])
Terminal 印出
DPP
KMT
TPP
GT
------------------------------------------
candidates={
"Lai":"DPP",
"Hou":"KMT",
"Ko":"TPP",
"Guo":"GT",
}
for i in candidates:
print(i)
Terminal 印出
Lai
Hou
Ko
Guo
--------------------------------------------
candidates={
"Lai":"DPP",
"Hou":"KMT",
"Ko":"TPP",
"Guo":"GT",
}
for i in candidates:
print(i,candidates[i])
Terminal 印出
Lai DPP
Hou KMT
Ko TPP
Guo GT
-----------------------------------------
candidates={
"Lai":"DPP",
"Hou":"KMT",
"Ko":"TPP",
"Guo":"GT",
}
for i in candidates:
print(i,candidates[i],sep=", ")
Terminal 印出
Lai, DPP
Hou, KMT
Ko, TPP
Guo, GT