Bird
0
0

Which of the following is the correct way to open a JSON file named data.json for reading in Python?

easy📝 Syntax Q12 of 15
Python - Structured Data Files

Which of the following is the correct way to open a JSON file named data.json for reading in Python?

Aopen('data.json', 'r')
Bopen('data.json', 'w')
Copen('data.json', 'a')
Dopen('data.json', 'x')
Step-by-Step Solution
Solution:
  1. Step 1: Understand file modes

    'r' mode opens a file for reading, 'w' for writing, 'a' for appending, 'x' for creating new file.
  2. Step 2: Choose mode for reading JSON

    To read JSON data, the file must be opened in 'r' mode.
  3. Final Answer:

    open('data.json', 'r') -> Option A
  4. Quick Check:

    Read mode = 'r' [OK]
Quick Trick: Use 'r' mode to read files [OK]
Common Mistakes:
  • Using 'w' which overwrites the file
  • Using 'a' which appends data
  • Using 'x' which fails if file exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes