Access Items
Learn all about Access Items in this comprehensive tutorial.
- •You can access the items of a dictionary by referring to its key name, inside square brackets:
- •The keys() method will return a list of all the keys in the dictionary.
- •The values() method will return a list of all the values in the dictionary.
- •The items() method will return each item in a dictionary, as tuples in a list.
- •To determine if a specified key is present in a dictionary use the in keyword:
Accessing Items
You can access the items of a dictionary by referring to its key name, inside square brackets:
There is also a method called get() that will give you the same result:
Get Keys
The keys() method will return a list of all the keys in the dictionary.
The list of the keys is a view of the dictionary, meaning that any changes done to the dictionary will be reflected in the keys list.
Get Values
The values() method will return a list of all the values in the dictionary.
The list of the values is a view of the dictionary, meaning that any changes done to the dictionary will be reflected in the values list.
Get Items
The items() method will return each item in a dictionary, as tuples in a list.
The returned list is a view of the items of the dictionary, meaning that any changes done to the dictionary will be reflected in the items list.
Check if Key Exists
To determine if a specified key is present in a dictionary use the in keyword:
Module quiz
2 questionsWhich of the following is true about Access Items?
What is the most common pitfall when working with Access Items?
Answer all questions to submit.