Skip to content
Advertisement

Is there a way to clear your printed text in python?

I have wanted for a long time to find out how to clear something like print(“example”) in python, but I cant seem to find anyway or figure anything out.

JavaScript

Now I need to clear it, and write some new text.

JavaScript

It would print.

Hey

JavaScript

But I want to clear the “Hey” so the user shouldnt look at both at same time, and it looks kinda messy.

Advertisement

Answer

JavaScript

Or os.system('clear') on unix (mac and linux). If you don’t want the scroll up either, then you can do this:

os.system("printf '33c'") should get rid of scroll back too. Something that works on all systems:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement