9 Python Dictionaries
9 Python Dictionaries
Dictionaries
At the end of this lesson…
• Access Items
• Change Values
• Loop through a dictionary
• Check if key exists
• Dictionary Lengths
• Remove, Add, Copy
• Nested Dictionary
Dictionary
You can access the items of a dictionary by referring to its key name, inside
square brackets:
• Get the value of the "model" key:
Accessing Items
There is also a method called get() that will give you the same result:
Change Values
You can change the value of a specific item by referring to its key name:
• Change the "year" to 2018:
Loop Through a Dictionary
Adding an item to the dictionary is done by using a new index key and
assigning a value to it:
Removing Items
• The del keyword removes the item with the specified key
name:
Removing Items
Python has a set of built-in methods that you can use on dictionaries.
THANK YOU!