Python Tutorials · Python Dictionaries

Access Items

Learn all about Access Items in this comprehensive tutorial.

5 min read beginner
  • 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:

python

There is also a method called get() that will give you the same result:

python

Get Keys

The keys() method will return a list of all the keys in the dictionary.

python

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.

python

Get Values

The values() method will return a list of all the values in the dictionary.

python

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.

python
python

Get Items

The items() method will return each item in a dictionary, as tuples in a list.

python

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.

python
python

Check if Key Exists

To determine if a specified key is present in a dictionary use the in keyword:

python

Module quiz

2 questions
1

Which of the following is true about Access Items?

2

What is the most common pitfall when working with Access Items?

Answer all questions to submit.