Is there a way to clear typed text in python?

Hi guys, I have long wanted to know how to clear something like print ("example") in python, but I cannot find anything or something like that.

print("Hey")
>Hey

Now I need to clear it and write a new text.

print("How is your day?")

He will print.

Hey,

>How is your day?

But I want to clear “Hey,” so the user does not have to look at both at the same time, and looks a little dirty.

+4
source share
1 answer
import os
os.system('cls')

Or os.system('clear')on unix (mac and linux). If you do not want to scroll up, then you can do this:

os.system("printf '\033c'")should also get rid of scrolling. Something that works on all systems:

import os
os.system('cls' if os.name == 'nt' else "printf '\033c'")
+7
source

All Articles