CBSE Class 12 Computer Science Question 117 of 145

File Handling — Question 13

Back to all questions
13
Question

Question 13

What is the output of the following considering the file data.csv given below.

    File data.csv contains:
Identifier;First name;Last name
901242;Riya;Verma
207074;Laura;Grey
408129;Ali;Baig
934600;Manit;Kaur
507916;Jiva;Jain
import csv
with open('C:\data.csv', 'r+') as f: 
  data = csv.reader(f)
  for row in data: 
      if 'the' in row :
          print(row)
Answer

This code will produce no output.

Explanation

By default, csv.reader() uses a comma (,) as the delimiter to separate values in a CSV file. But the delimiter in the file data.csv is semicolon (;), hence the rows won't split correctly, leading to each row being treated as a single string. When the code checks if the row contains the word 'the', it will only print rows where 'the' appears in the entire row. Therefore, the given code will not output anything.