- Make a system call with ‘clear’ in Linux and ‘cls’ in Windows as an argument.
- Store the returned value is an underscore or whatever variable you want (an underscore is used because python shell always stores its last output in an underscore).
# import only system from os
from os import system, name
# import sleep to show output for some time period
from time import sleep
# define our clear function
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name14 is 'posix')
_ = system('clear')
# print out some text
# sleep for 2 seconds after printing output
# now call function we defined above