Bird
0
0

Given accounts.csv content:

medium📝 Predict Output Q5 of 15
Selenium Python - Data-Driven Testing
Given accounts.csv content:
user,pass
john,abc123
jane,

What will this code print?
import csv
with open('accounts.csv', 'r') as f:
    reader = csv.DictReader(f)
    for row in reader:
        print(row['user'], row['pass'])
Ajohn abc123\njane
Bjohn abc123\njane None
Cjohn abc123\njane error
Djohn error\njane error
Step-by-Step Solution
Solution:
  1. Step 1: Understand DictReader behavior

    Missing CSV fields are read as empty strings, not None or error.
  2. Step 2: Analyze output

    First row prints 'john abc123', second prints 'jane ' (empty password).
  3. Final Answer:

    john abc123\njane -> Option A
  4. Quick Check:

    Empty CSV fields become empty strings [OK]
Quick Trick: Missing CSV fields read as empty strings [OK]
Common Mistakes:
  • Assuming missing fields become None
  • Expecting an error on missing values
  • Confusing field names in DictReader

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes