CBSE Class 12 Computer Science Question 99 of 136

Data File Handling — Question 38

Back to all questions
38
Question

Question 38

How are the following codes different from one another?

1.

fp = open("file.txt", 'r')  
fp.read()

2.

fp = open("file.txt", 'r')
Answer

The first code opens 'file.txt' in read mode, initializes a file object (fp) for further file operations, and reads its entire content using fp.read(). The second code also opens 'file.txt' in read mode, initializes a file object (fp) for further file operations, but it doesn't perform any read operation.