How to put spaces between values in a print() statement for example:
for i in range(5):
print(i, sep='', end='')
prints
012345
I would like it to print
0 1 2 3 4 5
While others have given an answer, a good option here is to avoid using a loop and multiple print statements at all, and simply use the *
operator to unpack your iterable into the arguments for print:
>>> print(*range(5))
0 1 2 3 4
As print()
adds spaces between arguments automatically, this makes for a really concise and readable way to do this, without a loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With