#PYTHON(DAY29)
File Handling(read() method)
Definition and Usage
Python provides the various function to read the file, but we will use the most common read() function. It takes an argument called size, which is nothing but a given number of characters to be read from the file. If the size is not specified, then it will read the entire file.
The read() method returns the specified number of bytes from the file. Default is -1 which means the whole file.
Syntax:
file.read()
Parameter Values:
Parameter : size
Description : Optional. The number of bytes to return. Default -1, which means the whole file.
Example :
Read the content of the file “demofile.txt”:
f = open("demofile.txt", "r")
print(f.read(33))
And the output is:
Hello! Welcome to demofile.txt
Th
No comments:
Post a Comment