How do you make a clear() function?
I was making a peice of work with some of my freinds and i was wondering how i could make a clear funcion. because i cant seem to find one that clears all of the text in the terminal or one that looks nice. could you please help and thanks for your time!
edit: I would just like to say, it may not be pssible to clear the text in terminal but i would like it to look like it did . Thanks also, @Bookie0 could you help lmao.
There is a better way:
def clear(seconds = 0): time.sleep(seconds) os.system('clear')
Then you use it like this:
Or type inside the parenthesis the seconds you want it to wait
Number 2 is only an example
Now you can make it wait before clearing if you want too!
Hope it helped
You just have to do this:
import os print('something') os.system('clear') # clears the screen after printing something
clear_system = lambda: os.system('clear') # then call the clear_system() function anywhere in your program print('something.......') clear_system()
import os #importing os def clear(): # putting it in a function so you can use it many times os.system('clear') # clears console # to use it: clear() # clears the console
Just do what everyone else is telling you to do:
def clear(): import system os.system("clear")
And to use it just do:
import time print("This text will disappear in 5 seconds!") time.sleep(5) clear()