Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
Python - Structured Data Files

What will be the output of this code?

import json

person = {'name': 'Anna', 'age': 25}
json_str = json.dumps(person)
print(type(json_str))

A<class 'str'>
B<class 'dict'>
C<class 'list'>
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand json.dumps() output type

    json.dumps() converts a Python dict to a JSON formatted string.
  2. Step 2: Check the printed type

    The variable json_str is a string, so type(json_str) is <class 'str'>.
  3. Final Answer:

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

    json.dumps() returns string type [OK]
Quick Trick: json.dumps() returns a string, not a dict [OK]
Common Mistakes:
  • Assuming json.dumps returns dict
  • Expecting list type output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes