pi_string and removes the newline character from each line at we print this string and also show how long the string is the variable pi_string contains the whitespace that was on the left side of the digits in each linebut we can get rid of that by using strip(instead of rstrip()filename 'pi_ _digits txtwith open(filenameas file_objectlines file_object readlines(pi_string 'for line in linespi_string +line strip(print(pi_stringprint(len(pi_string)now we have string containing pi to decimal places the string is characters long because it also includes the leading and decimal point note when python reads from text fileit interprets all text in the file as string if you read in number and want to work with that value in numerical contextyou'll have to convert it to an integer using the int(function or convert it to float using the float(function large filesone million digits so far we've focused on analyzing text file that contains only three linesbut the code in these examples would work just as well on much larger files if we start with text file that contains pi to , , decimal places instead of just we can create single string containing all these digits we don' need to change our program at all except to pass it different file we'll also print just the first decimal placesso we don' have to watch million digits scroll by in the terminalpi_string py filename 'pi_million_digits txtwith open(filenameas file_objectlines file_object readlines(files and exceptions