Q. What is the output of the following considering the file data.csv given on the right


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 =

It will not give any output, because data.csv did not contain “the” word.

3 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Hello! The above file might give an error as the absolute path contains single backslashes (\) which are treated as escape sequences. The corrected code should be:
    with open('C:\\data.csv','r+') as f:

    ReplyDelete
    Replies
    1. I have created data.csv file at given location.

      Delete
  2. The above file might give an error as the absolute path contains single backslashes (\) which are treated as escape sequences. The corrected code should be:
    with open('C:\\data.csv','r+') as f:

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post