All Python Tutorial Links

How to clear console/screen in Python?

 Clear Console/Screen in Python

Hello programmers!
In this tutorial, I will teach you how to clear console in Python. If you have any questions then comment below. So, let's get started.

Often we need to clear the console in python. But, most of the beginners don't know how to do this. We can do this with the help of the 'os' module.

Example-1:

from os import system
print("Hello")
system('cls')
print("Hi")

Output:

Hi

In the above code, we have imported the system class from the os module. Then we have 
printed "Hello" then we have clear the console then we have printed "Hi". You will only see 
hi after running this programe. 

Congratulations! Now you know how to clear the console in python. It's a very easy concept 
of python. But, most of us don't know it. So, if you can then share this blog:) If you have any
question then comment below. 

Happy Coding :)



Python
Print Colors in Python terminal
How to clear screen in python?
set clear() in python
set add() in python
Sets in Python
Ternary Operator in Python
Division Operators in Python
Operator Overloading in Python
Any All in Python
Operator Functions in Python | Set 1
Operator Functions in Python | Set 2
Difference between == and is operator in Python
Python Membership and Identity Operators
Python | Set 3 (Strings, Lists, Tuples, Iterations)
Python String
Python Lists
Python Tuples
Python Sets
Python Dictionary
Python Arrays
Python | Using 2D arrays/lists the right way
Multi-dimensional lists in Python
Convert Python Nested Lists to Multidimensional NumPy Arrays
Convert Python List to numpy Arrays
Python map() function
Taking input in Python
Iterate over a list in Python
Enumerate() in Python
Most of the time, while working with python interactive shell/terminal (not a console), we end up with a messy output and want to clear the screen for some reason. In an interactive shell/terminal, we can simply use
But, what if we want to clear the screen while running a python script. Unfortunately, there’s no built-in keyword or function/method to clear the screen. So, we do it on our own.
Store the returned value in an underscore or whatever variable you want (an underscore is used because python shell always stores its last output in an underscore).
Python Programming Foundation
Python DS
Getting screen's height and width using Tkinter | Python
Python | Multiple Sliders widgets Controlling Background Screen or WindowColor in Kivy
Python PIL | ImageChops.screen() and ImageChops.offset() method
Python | How to download windows lock-screen wallpapers
Replace Green Screen using OpenCV- Python
How to Get Coordinate Of Screen in Python Turtle ?
Python Tweepy - Getting the screen name of a user
turtle.Screen().bgcolor() function in Python
Python - turtle.Screen().setup() method
turtle.Screen().turtles() function in Python
Python VLC MediaPlayer - Toggling Full Screen
Python VLC MediaPlayer – Setting Full Screen Status
Python VLC MediaPlayer – Getting Full Screen Status
Python program to hide the mouse cursor on the Terminal screen
Create a Screen recorder using Python
Build an Application for Screen Rotation Using Python
How to Control Laptop Screen Brightness using Python?
Python Dictionary clear()
Different ways to clear a list in Python
Matplotlib.axes.Axes.clear() in Python
clear() element method - Selenium Python
python-modules
Most popular in Python
Python program to convert a list to string
Read a file line by line in Python
Reading and Writing to text files in Python
Python String | replace()
More related articles in Python
sum() function in Python
isupper(), islower(), lower(), upper() in Python and their applications
Python String | split()
Python | Get a list as input from user
append() and extend() in Python

Comments