How To Print Strings In A For Loop Without Space In One Line
I am wondering how can I print some strings in a for loop in one line without space between each other. I know concatenating strings without space in one line, but outside of a for
Solution 1:
s = ""for i in range(3):
s += 'Hi'print(s)
Solution 2:
You can achieve that by skipping print
and calling directly stdout
:
import sys
for i in range(3):
sys.stdout.write("Hi")
sys.stdout.write("\n")
Output result is HiHiHi
. See also this question for a lengthy discussion of the differences between print
and stdout
.
Post a Comment for "How To Print Strings In A For Loop Without Space In One Line"