Sometimes, we want to write output in same place on the console with Python.
In this article, we’ll look at how to write output in same place on the console with Python.
How to write output in same place on the console with Python?
To write output in same place on the console with Python, we call print
with the end
argument set to an empty string.
For instance, we write
import time
for i in range(100):
time.sleep(0.1)
print('Downloading File foo.txt [%d%%]\r'%i, end="")
to call print
with end
set to an empty string to print the text in the same line by overwriting the existing output.
Conclusion
To write output in same place on the console with Python, we call print
with the end
argument set to an empty string.