Access Dictionary Items

3 min read ·

Accessing dictionary items is a core Python skill, because dictionaries are used everywhere for structured and real-world data. Unlike lists or tuples, dictionary items are accessed using keys, not indexes.
This topic explains all correct ways to access dictionary items, from basic to advanced.

Access Dictionary Items Using Keys

The most direct way to access a value is by using its key.
If the key does not exist, Python raises an error.

Access Dictionary Items Using get() (Recommended)

The get() method is a safe way to access values.
You can provide a default value.

Access All Keys


Access All Values


Access Key–Value Pairs

Use items() to access both key and value together.

Check If Key Exists

Before accessing, you can check if a key exists.

Access Nested Dictionary Items


Access Nested Dictionary Using get()

This avoids errors if any key is missing.

Access Dictionary Items Using Loop

Keys Only


Values Only


Key–Value Together


Access Dictionary Items Using Index (Not Allowed)

Dictionaries do not support index-based access.

Convert Dictionary for Indexed Access

If index-based access is needed.

Common Mistakes

Accessing Missing Key Directly


Assuming Order Before Python 3.7


Best Practices

  • Use get() for safe access
  • Check key existence using in
  • Use items() for loops
  • Avoid index-based access
  • Use nested get() for deep dictionaries