350-401 · Question #1042
Refer to the exhibit. What is printed to the console when this script is run?
The correct answer is D. a key-value pair in string type. The script prints a string representation of the dictionary data because f-strings convert embedded expressions into their string equivalent.
Question
Exhibits
Options
- Aa key-value pair in tuple type
- Ban error
- Ca key-value pair in list type
- Da key-value pair in string type
How the community answered
(21 responses)- A5% (1)
- B5% (1)
- C19% (4)
- D71% (15)
Why each option
The script prints a string representation of the dictionary `data` because f-strings convert embedded expressions into their string equivalent.
The output is not a tuple type; it is a string representation of a dictionary.
The script is syntactically correct and will execute without generating an error.
The output is not a list type; it is a string representation of a dictionary.
When an f-string includes a dictionary object like `{data}`, Python's `__str__` method is implicitly called on the dictionary, converting it into its string representation. This results in the literal dictionary syntax, including keys, values, and curly braces, being embedded directly into the output string.
Concept tested: Python f-string dictionary representation
Source: https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals
Topics
Community Discussion
No community discussion yet for this question.

