Skip to main content
Robert David
Today I accept that for some people, I may be too much or too little. But for the people who deserve me, I am just right.
Asked a question 2 years ago

how to clear python console?

Where am I?

In answerQA you can ask and answer questions and share your experience with others!

Want to make a difference by making some contribution to open source community!
  1. Make a system call with ‘clear’ in Linux and ‘cls’ in Windows as an argument.
  2. 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

def clear():

# for windows

if name == 'nt':

 _ = system('cls')

# for mac and linux(here, os.name26 is 'posix')


 _ = system('clear')

# print out some text

print('hello geeks\n'*10)

# sleep for 2 seconds after printing output


# now call function we defined above



Related Questions