How to Clear Python Interpreter Console?
There is no direct way or command to clear python interpreter console. We might have heard about system call to clear console screen. For window system, ‘cls’ clears the console. ‘clear’ command works for Linux system. We can use these system calls t0 clear screen in python.
To call system call on python console, it requires os library to be imported. This os library comes inbuilt with python installation. There is no need to explicitly install.
Command to clear Python Interpreter Console on Window:
import os clear = lambda: os.system('cls') #on Windows System clear()
Command to clear Python Interpreter Console on Linux:
import os clear = lambda: os.system('clear') #on Linux System clear()
Note: “lambda” keyword in python is used to define anonymous functions. And these functions are also called as lambda functions.
You can find more Python tricks and command on CSEStack.
These commands are tested on python 3.4 version. It will work for both python 2.x and 3.x versions.
I am Python developer. I usually keep python interpreter console opened. Sometimes test command runs over it and creates cluttered print output on python console. These back log print command needs to be cleared. So use this trick to clear screen in Python.