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.
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:
- Create a Dictionary:
student = {"name": "John", "age": 20, "grade": "A"}
creates a dictionary with keys and corresponding values.
- Access Values:
print(student["name"])
prints the value associated with the key "name" in the dictionary.
- Run the Program:
- Execute the program and understand how to work with dictionaries.