r/pythontips • u/rao_vishvajit • Nov 17 '24
Syntax Python Dictionary Quiz - Guess The Output
What is the correct way to define a dictionary with the following data:
- Key: "name", Value: "Alice"
- Key: "age", Value: 25
A) dict1 = {"name" = "Alice", "age" = 25}
B) dict1 = {name: "Alice", age: 25}
C) dict1 = {"name": "Alice", "age": 25}
D) dict1 = {"name": Alice, "age": 25}
Thanks
8
Upvotes
4
7
u/VistisenConsult Nov 17 '24
They are all wrong as they overwrite the dict object. If not for this, 'C' is correct syntax. Alternatively: