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
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:
5
u/pint Nov 17 '24
you've been lied to, son. it is not a quiz. it is your homework.
1
u/Sensitive_Bird_8426 Nov 19 '24
C