0
Where is this text coming from?
When I run the code with open('file.txt') as file: line_number = 1 for line in file: print('{}: {}'.format(line_number, line.rstrip())) line_number += 1 Python outputs 1: This is line one. 2: This is line two. 3: Finally, we are on the third and last line of the file. How does it know what to say?! I never told it to print a string saying "This is line one". Also, why does it stop at three? Any help would be appreciated, thanks!
1 Odpowiedź
+ 3
Your code loads a text file and loops through the lines and prints them.