-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter 6
Jarlin Almanzar edited this page Oct 28, 2019
·
4 revisions
Def: A collection of key-value pairs. Each key is connect to a value, and you can use a key to access the value associated with that key.
A key can be:
- a number
- a string
- a list
- another dictionary
- any object created in python
A dictionary is wrapped in braces {} and a dynamic structure, thus you can add a new key-value pair at any time.
Dictionaries allow you to connect pieces of related information, can store a limitless amount of information, and model a variety of real-world objects.
alien_o = {"color": "green", "points":5}
print(alien_o["color"])
print(alien_o["points"])
alien_o = {"color": "green", "points":5}
print(alien_o["color"])
print(alien_o["points"])
alien_o["x_position"] = 0
alien_o["y_position"] = 25
print(alien_o)
alien_o = {"color": "green", "points":5}
print(alien_o["color"])
print(alien_o["points"])
alien_o["x_position"] = 0
alien_o["y_position"] = 25
alien_o["color"] = "blue"
print(alien_o)
del dict["name_of_key"]
alien_o = {"color": "green", "points":5}
print(alien_o["color"])
print(alien_o["points"])
alien_o["x_position"] = 0
alien_o["y_position"] = 25
alien_o["color"] = "blue"
del alien_o["points"]
print(alien_o)