Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Access Items

Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Access Items

Accessing Dictionary Items

In Python, you can easily access the values stored in a dictionary using the associated keys. Let’s explore different ways to do that.

I. Accessing Single Values

You can access a value by its key using:

  • Square brackets []

  • The get() method

				
					student = {'full_name': 'Areeba Khan', 'roll_no': 12, 'passed': True}

print(student['full_name'])      # Access using brackets
print(student.get('passed'))     # Access using get method

				
			

Output:

				
					Areeba Khan
True

				
			

Note: If the key doesn’t exist, [] gives an error, but .get() returns None.

2. Accessing All Values

Want to see just the values stored in the dictionary? Use the .values() method.

Example :
				
					student = {'full_name': 'Areeba Khan', 'roll_no': 12, 'passed': True}

print(student.values())

				
			

Output:

				
					dict_values(['Areeba Khan', 12, True])

				
			

3. Accessing All Keys

You can fetch only the keys from a dictionary using the .keys() method.

Example:
				
					student = {'full_name': 'Areeba Khan', 'roll_no': 12, 'passed': True}

print(student.keys())

				
			

Output:

				
					dict_keys(['full_name', 'roll_no', 'passed'])

				
			

4. Accessing Key-Value Pairs

If you want to view the entire content (keys with their values), the .items() method is your friend.

Example:
				
					student = {'full_name': 'Areeba Khan', 'roll_no': 12, 'passed': True}

print(student.items())

				
			

Output:

				
					dict_items([('full_name', 'Areeba Khan'), ('roll_no', 12), ('passed', True)])


				
			

Summary

  • Use [] or .get() to get individual values.

  • Use .values() to get all values.

  • Use .keys() to get all keys.

  • Use .items() to get key-value pairs.

This makes dictionaries powerful when you want to organize and retrieve data easily — and now you know how to access every part of them.

Scroll to Top