reading from files python provides two methods for extracting data from text fileboth of which extract data as strings to extract other types of data from text fileyou must explicitly convert the extracted string(sas was done with the input(function the readline(method is used to extract an entire line from text file the end of line is indicated by newline character (\nthe extracted text is returned as stringline infile readline(if the file is empty or the end of file has been reachedthe readline(method returns an empty string (""to flag this resultinfile open"data txt""rline infile readline(while line !"printline line infile readline(infile close(the readline(method leaves the newline character at the end of the string when the line is extracted from the file the rstrip(string method can be used to strip the white space from the endline infile readline(stripped line rstrip(to read individual characters from text filesimply pass an integer value to the readline(method indicating the number of characters to be extractedch infile readline read single character python provides the readlines(method that can be used to extract the entire contents of an open file and store it into string listlines infile readlines(an alternate approach to processing the entire contents of text file is with the use of the file iterator consider the following examplewhich extracts the input fileone line at timeand then writes it to the output fileinfile open"myreport txt""rfor line in infileprintline infile close(the previous examples dealt with the extraction of strings from text file but what if we need to extract numeric valuessince python only provides methods for extracting stringswe must handle the conversions explicitly consider the following sample text file containing three pieces of information for student