banner



How To Clear Screen In Python 3.7 0 Shell

[Simple Steps] How to Clear Python Interpreter Console Screen?

Do you use the Python interpreter console for practicing Python code?

You might have seen, there is no direct way or command to clear Python interpreter console.

No worries. There is indirect way of doing this. Let's see.

You can clear the Python interpreter console screen using a system call.

System calls to clear the console:

  • For the window system, cls clear the console.
  • For the Linux system, clear command works.

We can run these system calls through the Python to clear screen. It's simple.

To call the system calls through the Python console, we need the os library to be imported. This os library comes inbuilt with python installation. There is no need to explicitly install it.

Watch this video where I have demonstrated how you can clear the Python shell interpreter console.

Command to clear Python Interpreter Console on Window

Using Python Definition:

import os def clear(): os.system('cls') #on Windows System clear()            

If you know the basic Python syntax, this code is self explanatory.

Using Lambda Function:

import os clear = lambda: os.system('cls') #on Windows System clear()            

Command to clear Python Interpreter Console on Linux:

Using Python Definition:

import os def clear(): os.system('clear') #on Linux System clear()            

Using Lambda Function:

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.

What is Lambda Function here?

Above code is all about lambda function.

The "lambda" keyword in Python is used to define anonymous functions. And these functions are also called as lambda functions.

Learn more 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.

Clear Python Interpreter Console

What's Next?

You can run a Python program without using the 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.

I am a 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.

Related Articles:

  • 45+ Interesting Python Project Ideas
  • 60+ Interview Coding Questions

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.

Happy Pythoning!

Python Interview Questions eBook

Aniruddha Chaudhari

I am complete Python Nut, love Linux and vim as an editor. I hold a Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack.org portal.


Your name can also be listed here. Got a tip? Submit it here to become an CSEstack author.

How To Clear Screen In Python 3.7 0 Shell

Source: https://www.csestack.org/clear-python-interpreter-console/

Posted by: jarvisclinking.blogspot.com

0 Response to "How To Clear Screen In Python 3.7 0 Shell"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel