How to clear Python shell

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.


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263607.html

(0)
上一篇 2022年5月30日
下一篇 2022年5月30日

相关推荐

发表回复

登录后才能评论