Dictionaries Example

suggest change

Dictionaries map keys to values.

car = {}
car["wheels"] = 4
car["color"] = "Red"
car["model"] = "Corvette"

Dictionary values can be accessed by their keys.

print "Little " + car["color"] + " " + car["model"] + "!"
# This would print out "Little Red Corvette!"

Dictionaries can also be created in a JSON style:

car = {"wheels": 4, "color": "Red", "model": "Corvette"}

Dictionary values can be iterated over:

for key in car:
  print key + ": " + car[key]

# wheels: 4
# color: Red
# model: Corvette

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents