- readlines() is a python function used in file handling which read all line of the file and make a list of each line.
Syntax-
f=open('myfile.txt','r')
f.readlines()
-It return the list that contain the each line of the file.
Example-
file data is -
first
second
third
then readlines() return the ['first','second','third']
program-
#write data in file in multiple lines
f=open("myfile.txt",'w')
f.write("Firstn")
f.write("secondn")
f.write("Thirdn")
f.write("Fourthn")
f.write("Fiven")
f.write("Sixn")
f.close()
#read file line by line
f=open('myfile.txt','r')
print(f.readlines())
f.close()
['Firstn', 'secondn', 'Thirdn', 'Fourthn', 'Fiven', 'Sixn']