Text File - readlines() Function


☞ It reads the data line by line and stores it as an item of the list.

☞ It reads the the entire file content as a list of strings.

☞ The number of items in the list will be based on the number of lines written in the text files.

☞ After reading the file, pointer goes to the end of the file.

Example :

 
#reading lines from a text file 

def reading_data():
    f = open("demo.txt","r")
    L=f.readlines()  will return lines in the form of list of strings
    print(L)
    f.close()

reading_data()   #calling a function