Categories
Python Answers

How to have multiple prints on the same line in Python?

Spread the love

Sometimes, we want to have multiple prints on the same line in Python

In this article, we’ll look at how to have multiple prints on the same line in Python.

How to have multiple prints on the same line in Python?

To have multiple prints on the same line in Python, we can set the end argument of print to an empty string.

For instance, we write

def install():
    print("Installing...      ", end="", flush=True)

install()
print("[DONE]")

to call print with a string and the end argument set to an empty string in the install function.

Then we call install function to print "Installing... ".

And then we call print again to to print "[DONE]" on the same line since end is set to an empty string instead of a new line.

Conclusion

To have multiple prints on the same line in Python, we can set the end argument of print 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 *