Quiz: Python Dictionary
Practice Python dictionaries with this quiz. Covering key concepts like dictionary creation, access, update, deletion, and nesting.
1.
What is the correct way to define a dictionary in Python?
2.
What will be the output of the following code?
python
1 2
car = {"brand": "Toyota", "year": 2022} print(car["brand"])
3.
What happens if a dictionary is defined with duplicate keys?
4.
What does the following code print?
python
1 2 3
car = {"brand": "Tesla", "year": 2020} car["year"] = 2021 print(car["year"])
5.
What will this return?
python
1 2
car = {"brand": "BMW", "year": 2019} print(len(car))
6.
How do you access a nested dictionary item?
python
1
family = {"child": {"name": "Alice"}}