KnowledgeBoat Logo

Computer Science

How are the following codes different from one another?

1.

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

2.

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

Python Data Handling

1 Like

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.

Answered By

2 Likes


Related Questions