Accessing Items
Lesson 4 of 14 in Coddy's Dictionary in Python course.
To access the values in a dictionary refer to its key name, inside square brackets,
my_dict = {"name": "Alice", "age": 30, "city": "New York"}
print(my_dict["name"]) # Output: "Alice"
print(my_dict["age"]) # Output: 30Challenge
EasyYou are given a dictionary, your task is to access all the items in the dictionary and print its value, keep the dictionary values order!
Try it yourself
# The book dictionary
book = {
"title": "Python for Beginners",
"author": "Alice Smith",
"year": 2022,
"pages": 200,
"genre": "Programming",
"publisher": "Tech Books Inc."
}
# Write code hereAll lessons in Dictionary in Python
2Operations
Create DictionaryAccessing ItemsChange ValuesAdding ItemsRemoving ItemsCheck if a key existsLoop Through a Dictionary