Skip to main content
"The only way to do great work is to love what you do. If you haven't fount it yet, keep looking. Don't Settle,"
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.name15 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