Home >>Python File Methods >Python File read() Method

Python File read() Method

Python File read() Method

Python File read() Method is used to returns the specified number of n bytes size from the associated file. The whole file default value is -1.

Syntax:
file.read()

Parameter Values

Parameter Description
size It is Optional. Return the number of bytes.
Here is an Example of Python File read() Method:

z = open("file1.txt", "r")
print(z.read())

Output:
Hello! Welcome to file1.txt
This file is for testing purposes.
Good Luck!
Example 2:

x = open("file2.txt", "r")
print(x.read())

Output:
Hello! Welcome to file2.txt
This file is for testing purposes.
Good Luck!