Python Clear Screen Tutorial

In this tutorial, we will learn clear() in python programming. In python clear screen is used to clear the screen of the console by just calling the clear() function. We will learn the core idea of the clear() function with implementation in python console. In python programming language you should know about all the functions to work easily. So start learning from today.

Python clear screen

Normally people clear screen by just pressing ctrl + l in a python shell or terminal. In python terminal, the clear() function is easy to use, But if in python script console ctr+l not work. So for that, you should create a function to clear the screen of the console.

python clear screen function


  • import os
  • clear = lambda : os.system(‘cls’)
  • clear()

In python script, first import os library in the program and then create the clear() function clear = lambda : os.system(‘cls’) and when required for to clear screen, just call the clear() function. clear() function is mostly used in the python program to clear screen.

Example to clear screen in program


# Program to clear screen
import os
clear = lambda:os.system('cls')
name = input("Enter your name : ")
print("hello, ", name)
input('press enter the exit.')

In the python clear screen program, we are implementing the clear() function. In code, first importing the os and then creating the function after that apply clear() function when required. As you can see in the code clear function is used to clear all the output before it and execute the further line of code.

python clear screen in cmd

In command shell, Run the program by just using .py script in python. Syntax : python Enter the required value and press enter, so the clear function call to clear the screen and after that printing the name.

Python clear screen result

As you can see in the screenshot, all the screen are clear when the clear() function execute.

Follow these steps to implement the program in your python console window. And if you are working in the terminal, directly press clrl + l to clear the screen of the shell but you cannot use ctrl + l directly in the terminal. So for that follow the following steps to clear screen are given below.

How To Clear Python Console Screen

Python clear screen

In this tutorial, we will learn how to clear the python console screen. Python clear screen is used to clear the screen by just calling the function clear(). Follow these steps to python clear screen :

Step 1

python clear screen import os

In python script console, You should first import the library called os in your program.
Syntax: import os.

Step 2

python clear screen function

Create a new function clear, by using lambda function,
Syntax: clear = lambda: os.system(‘cls’)

Step 3

Python clear screen clear()

whenever you have required to clear the screen, just call the clear() function.
syntax: clear()

There is one another method, to clear the screen with the help of the subprocess module. But subprocess module is a bit difficult to implement for clearing the screen. So you should use the normal method to python clear screen. In the normal method, The function is created with the help of python os library. In python programming, clear() function is used to just clear all the miscellaneous data above the line. So, I recommend you to follow the normal method to clear the screen.

FAQ for python clear screen

How to python clear screen console work?

In python programming, the console screen can clear by using clear() function.
Steps to clear screen:
1) import os
2) create clear function clear = lambda: os.system(‘cls’)
3) call clear() function when required.

What is the use of clear() function?

In python, clear() function is used to clear the screen of the console.

Learn more python tutorial

Video Tutorial for Clear Screen in Python

If you have any query please ask in the comment section, I will be happy to answer you.

5 thoughts on “Python Clear Screen Tutorial”

  1. It’s appropriate time to make some plans for the long run and it’s time to be happy.
    I have read this put up and if I could I want to counsel you some
    fascinating things or advice. Perhaps you could write next articles regarding
    this article. I wish to read even more issues about it!


Leave a Comment

Share via
Copy link
Powered by Social Snap