read(returns the entire remaining contents of the file as single (potentially largemulti-linestring readline(returns the next line of the file that is all text up to and including the next newline character readlines(returns list of the remaining lines in the file each list item is single line including the newline character at the end here' an example program that prints the contents of file to the screen using the read operationprintfile py prints file to the screen def main()fname input("enter filename"infile open(fname," "data infile read(print(datamain(the program first prompts the user for file name and then opens the file for reading through the variable infile you could use any name for the variablei used infile to emphasize that the file was being used for input the entire contents of the file is then read as one large string and stored in the variable data printing data causes the contents to be displayed the readline operation can be used to read the next line from file successive calls to readline get successive lines from the file this is analogous to inputwhich reads characters interactively until the user hits the keyeach call to input gets another line from the user one thing to keep in mindhoweveris that the string returned by readline will always end with newline characterwhereas input discards the newline character as quick examplethis fragment of code prints out the first five lines of fileinfile open(somefile" "for in range( )line infile readline(print(line[:- ]notice the use of slicing to strip off the newline character at the end of the line since print automatically jumps to the next line ( it outputs newline)printing with the explicit newline at the end would put an extra blank line of output between the lines of the file alternativelyyou could print the whole linebut simply tell print not to add it' own newline character print(lineend=""