Editor

Create a Dictionary and Access a Value

Beginner · Write the code · from Python Dictionaries: The Complete Guide with Real Examples

From the lesson: Python Dictionaries: The Complete Guide with Real Examples

Open the contacts app on your phone. You look up a person by name and get their phone number. You don't search by position - you don't say "give me contact number 47." You search by name.

Read the lesson

Create a dictionary called pet with these key-value pairs:

  • 'name': 'Buddy'
  • 'species': 'dog'
  • 'age': 5
  • Then print the pet's name.

    Expected output:

    Buddy
    # Create the pet dictionary
    # Print the pet's name

    More Dictionaries exercises

    All Python exercises · 50 practice problems · Data Structures quiz