How to clear Python shell
Sometimes working with the Python shell, we got haphazard output or wrote unnecessary statements, and we want to clear the screen for some other reason.
The "cls" and "clear" commands are used to clear a terminal (terminal window). If, you are using the shell within IDLE, which won't be affected by such things. Unfortunately, there is no way to clear the screen in IDLE. The best you could do is to scroll the screen down lots of lines.
For example -
Though you could put this in a function:
And then call it when needed as cls() function. It will clear the console; all previous command will be vanished and screen start from the beginning.
If you are using a Linux, then -
If you're using Windows-
We can also do it using the Python script. Consider the following example.
Note - An underscore variable is used because Python shell always stores its last output in the underscore.
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week