Bird
0
0

You want to import the 'json' module with alias 'js' and use it to convert a dictionary to a JSON string. Which code is correct?

hard📝 Application Q8 of 15
Python - Modules and Code Organization
You want to import the 'json' module with alias 'js' and use it to convert a dictionary to a JSON string. Which code is correct?
Aimport json as js print(json.dumps({'a':1}))
Bimport json as js print(js.dumps({'a':1}))
Cimport js as json print(js.dumps({'a':1}))
Dimport json print(js.dumps({'a':1}))
Step-by-Step Solution
Solution:
  1. Step 1: Correct import alias syntax

    Use 'import json as js' to alias json module as js.
  2. Step 2: Use alias to call dumps

    Call js.dumps() to convert dict to JSON string.
  3. Final Answer:

    import json as js\nprint(js.dumps({'a':1})) -> Option B
  4. Quick Check:

    Alias used consistently for module functions [OK]
Quick Trick: Use alias name to call module functions after aliasing [OK]
Common Mistakes:
  • Calling original module name after aliasing
  • Swapping alias and module names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes