Categories
Python Answers

How to write output in same place on the console with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *