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 the 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()
Don’t Just Copy Paste the Code:
Why am I saying that?
If you copy paste the code, I am pretty sure you will forget this code and then tomorrow again you will do a Google Search.
The best way is to understand the code written above. It is pretty simple to remember and write code if you know how it has implemented.
It is just lambda function. The “lambda” keyword in Python is used to define anonymous functions. And these functions are also called as lambda functions. Know about lambda function you can write many such codes with no more hustle. It is extremely useful.
These commands are tested on Python 3.4 version. It will work for both Python 2.x and 3.x versions.
You can run a Python program without using Python interpreter console. Install free text editor for your system (Linux/Windows/Mac). And now you can run the Python program from Windows’s command prompt or Linux’s terminal.
You can find more Python tricks and command on CSEstack.
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 backlog print command needs to be cleared. So use this trick to clear screen in Python.
Programming Tip: Programmers can now be 24*7 productive by remotely accessing their essential programming tools such as emulators and IDE`s on the preferred device(PC/Android/iOS) using high-performance citrix xendesktop at an affordable xendesktop pricing from CloudDesktopOnline. If you prefer a dedicated server hosting, try out dedicated gpu hosting from Apps4Rent with 24*7 impeccable tech-support.
Hope you find this quick commands and guide useful for your Python learning. Is there anything I can help you with? Feel free to write in the comment section below.