Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q4 of 15
Selenium Python - Data-Driven Testing
What will be the output of this code snippet?
import csv
with open('data.csv', 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        print(row)

Assuming data.csv contains:
name,age
John,30
Jane,25
Aname,age\nJohn,30\nJane,25
B['name', 'age']\n['John', '30']\n['Jane', '25']
Cname age\nJohn 30\nJane 25
DError: csv.reader requires delimiter argument
Step-by-Step Solution
Solution:
  1. Step 1: Understand csv.reader output

    The csv.reader returns each row as a list of strings split by commas.
  2. Step 2: Match output with printed rows

    Printing each row prints a list like ['name', 'age'], then ['John', '30'], etc.
  3. Final Answer:

    ['name', 'age']\n['John', '30']\n['Jane', '25'] -> Option B
  4. Quick Check:

    csv.reader returns list rows = C [OK]
Quick Trick: csv.reader returns each row as a list [OK]
Common Mistakes:
  • Expecting string output instead of list
  • Confusing print output with file content
  • Thinking delimiter argument is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes