I would like to make several statements that give standard output without seeing newlines in between statements.
Specifically, suppose I have:
for item in range(1,100):
print item
The result is:
1
2
3
4
.
.
.
How get this to instead look like:
1 2 3 4 5 ...
Even better, is it possible to print the single number over the last number, so only one number is on the screen at a time?
Answer
Change print item
to:
print item,
in Python 2.7print(item, end=" ")
in Python 3
If you want to print the data dynamically use following syntax:
print(item, sep=' ', end='', flush=True)
in Python 3
No comments:
Post a Comment