Bird
Raised Fist0

Which of the following is the correct way to open a CSV file for reading in Python?

easy📝 Syntax Q12 of Q15
Python - Structured Data Files
Which of the following is the correct way to open a CSV file for reading in Python?
Aopen('data.csv', 'a')
Bopen('data.csv', 'w')
Copen('data.csv', 'r')
Dopen('data.csv', 'x')
Step-by-Step Solution
Solution:
  1. Step 1: Understand file modes in Python

    The mode 'r' means open for reading, which is needed to read a CSV file.
  2. Step 2: Check other modes

    'w' is for writing (overwrites), 'a' is for appending, and 'x' is for creating a new file. None are for reading existing files.
  3. Final Answer:

    open('data.csv', 'r') -> Option C
  4. Quick Check:

    Use 'r' mode to read files [OK]
Quick Trick: Use 'r' mode to read files [OK]
Common Mistakes:
MISTAKES
  • Using 'w' which overwrites 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