How To read File in python

Working with text files is easy in Python. The first step is to associate a file with a variable using the
open function.
<filevar> = open(<name>, <mode>)
Here name is a string that provides the name of the file on the disk. The mode parameter is either the string
"r" or "w" depending on whether we intend to read from the file or write to the file.
For example, to open a file on our disk called “numbers.dat” for reading, we could use a statement like
the following.
infile = open("numbers.dat", "r")
Now we can use the variable infile to read the contents of numbers.dat from the disk.
Python provides three related operations for reading information from a file:
<filevar>.read()
<filevar>.readline()
<filevar>.readlines()
The read operation returns the entire contents of the file as a single string. If the file contains more than one
line of text, the resulting string has embedded newline characters between the lines.