Home > front end >  Why does the end=' ' argument in print() get printed twice when used in a loop?
Why does the end=' ' argument in print() get printed twice when used in a loop?

Time:12-21

There is a text file that I am reading from.

for line in file:
    print(line, end='1')

The keyword argument '1' gets printed twice - once at the end of each line as expected but another at the beginning of the next line.

the output

this is the output

CodePudding user response:

Your Textfile probably contains empty lines between those sentences. Those empty lines will get printed as well with a "1" at the end.

  • Related