Bird
0
0

Which of the following is the correct syntax to read a CSV file using csv.reader?

easy📝 Syntax Q3 of 15
Python - Structured Data Files
Which of the following is the correct syntax to read a CSV file using csv.reader?
Awith open('file.csv', 'r') as f: reader = csv.reader(f) for row in reader: print(row)
Bwith open('file.csv', 'w') as f: reader = csv.reader(f) for row in reader: print(row)
Creader = csv.reader('file.csv') for row in reader: print(row)
Dwith open('file.csv', 'r') as f: reader = csv.writer(f) for row in reader: print(row)
Step-by-Step Solution
Solution:
  1. Step 1: Check file mode for reading CSV

    To read a CSV file, open it in read mode ('r').
  2. Step 2: Use csv.reader correctly

    Pass the file object to csv.reader and iterate over rows to print them.
  3. Final Answer:

    Open file in 'r' mode, use csv.reader, iterate rows -> Option A
  4. Quick Check:

    csv.reader needs file opened in read mode [OK]
Quick Trick: Open CSV files in 'r' mode to read with csv.reader [OK]
Common Mistakes:
  • Opening file in write mode when reading
  • Passing filename string directly to csv.reader
  • Using csv.writer instead of csv.reader for reading

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes