Print On The Same Line With Python
1 min read

Printing on the same with Python is not that difficult, it did, however, take some time before I managed to find the best way to do it myself. This is a neat little trick and I tend to use it quite a lot in my programs.

print("hello", end="\r", flush=True)

Example

I have written a quick example, with the following code:

import time

for i in range(10):
    print(i, end="\r", flush=True)
    time.sleep(0.5)

It looks like this.

Flush python