Read File In Python

Method read() reads at most size bytes from the file and read hits the end of the file before obtaining size bytes, then it reads only available bytes.

read_file.txt input file

input file.txt
In the below program example, we are opening a text file with read mode, and read mode has this read method that read the entire file content from beginning to end. The open method accepts two parameters file path and file mode to open.
def read_file_content(filename):
    file = open(filename, 'r+')
    file_data = file.read()
    print(file_data)

filename = "input_file.txt"
read_file_content(filename)

Output:

output data