Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q4 of 15
Python - Structured Data Files
What will be the output of the following code?
import json
py_obj = {'x': 10, 'y': 20}
json_str = json.dumps(py_obj)
print(type(json_str))
A<class 'bytes'>
B<class 'dict'>
C<class 'str'>
D<class 'list'>
Step-by-Step Solution
Solution:
  1. Step 1: Understand json.dumps() output type

    json.dumps() converts a Python object into a JSON formatted string, so the result is a string.
  2. Step 2: Check the printed type

    Printing type(json_str) will show <class 'str'>.
  3. Final Answer:

    <class 'str'> -> Option C
  4. Quick Check:

    json.dumps() output type = str [OK]
Quick Trick: dumps() returns a string, loads() returns Python object [OK]
Common Mistakes:
  • Expecting a dict instead of string
  • Confusing dumps() with load()
  • Thinking output is bytes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes