Python Lesson: Dictionaries

Dictionaries provide a way to store key-value pairs, allowing us to associate information with specific keys. In this example, we create a dictionary and demonstrate how to access values using keys.

Python Lesson: Dictionaries

Introduction:


Dictionaries provide a way to store key-value pairs, allowing us to associate information with specific keys. In this example, we create a dictionary and demonstrate how to access values using keys.

# Lesson: Dictionaries
student = {"name": "John", "age": 20, "grade": "A"}
print(student["name"])

Tutorial:

  1. Create a Dictionary:
    • student = {"name": "John", "age": 20, "grade": "A"} creates a dictionary with keys and corresponding values.
  2. Access Values:
    • print(student["name"]) prints the value associated with the key "name" in the dictionary.
  3. Run the Program:
    • Execute the program and understand how to work with dictionaries.