with open('example.txt', 'r') as file:
contents = file.read()
print(contents)
This code will read the entire contents of the example.txt file and print it to the console.
You can also read the contents of a file line by line using the readline() method. Here's an example:
with open('example.txt', 'r') as file:
line = file.readline()
while line:
print(line)
line = file.readline()
This code will read the example.txt file line by line and print each line to the console.
I hope it will help you. Thank you :)
For more refer link: https: