Javatpoint Logo
Javatpoint Logo

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.

Example -

Note - An underscore variable is used because Python shell always stores its last output in the underscore.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA