字典示例
字典將鍵對映到值。
car = {}
car["wheels"] = 4
car["color"] = "Red"
car["model"] = "Corvette"
可以通過鍵訪問字典值。
print "Little " + car["color"] + " " + car["model"] + "!"
# This would print out "Little Red Corvette!"
字典也可以以 JSON 樣式建立:
car = {"wheels": 4, "color": "Red", "model": "Corvette"}
字典值可以迭代:
for key in car:
print key + ": " + car[key]
# wheels: 4
# color: Red
# model: Corvette