Flash Sale: Flat 70% + Addl. 25% Off on all Courses | Use Coupon DS25 in Checkout | Offer Expires In

  Enroll Now

Searching in Files

We can search in the file line by line or by creating a single string for the whole content of the file.

check = 0
with open("/cxldata/python_sample_file") as f:
    for line in f:
        if(line.startswith('w')):
            check = check + 1

startswith function checks if the string is starting with the argument mentioned in the brackets.

Basically, here were searching for the lines in the file which are starting with 'w'.

Can you tell the value of check after the above code is executed?


No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...