► Python program to open a text file and read the text in it


Steps followed:
1. first open an existing file in read mode
2. read the file and store the value in a variable
3. print the variable


Program

#Python program to open a text file and read the text in it

#open an existing file in read mode
with open("test_file.txt","r") as myfile:
    #read the file and store the value in a variable
    content=myfile.read()
    #print the variable
    print(content)
 


Output

the above code will print the content of the file





Also Read: