Skip to content
← Back to Community
clear
Profile icon
owenbaseball

How do I clear only part of the screen in python

Answered by RYANTADIPARTHI [earned 5 cycles]
View Answer
Voters
Profile icon
DawidKupniewski
Profile icon
JasonXue
Profile icon
TheDevBest
Profile icon
owenbaseball
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

Do you mean only one part? If that's what you mean, then you can't do it. THe entire screen has to be cleared.

import os os.system('clear')

or

clear()

Any of them should work

Profile icon
Bookie0

@RYANTADIPARTHI

clear() won't just work like that, you have to put it in a function first

Profile icon
InvisibleOne

what part of the screen do you not want cleared?

Profile icon
Bookie0

Using this:

import os os.system('clear') # clears all of the console (black part)

You can use it whenever you want, or put it into a function:

import os def clear(): # defining the function os.system('clear') clear() # calls the function, and clears console

This will clear everything on the console, so if your wanted certain parts of your console cleared, that won't be possible unfortunately.

You could always just re-print the stuff you want to keep on the console, ie:

import os def clear(): os.system('clear') # if you just want 'Hello there!' to be cleared # but you want 'How are you?' to stay # you could maybe output it again, but it would be kinda troublesome print("Hello there!") print("How are you?") clear() # clears everything from console print("How are you?") # outputs 'How are you?' again (change it to what you want to remain) name = input("Enter your name ") # an input asking for your name
Profile icon
Coder100

You can't. You can only clear all of the screen or none of the screen.

import os def clear(): os.system("clear") print("Hello,") input() clear() print("World!")
Profile icon
Michael8910

if you want to clear the output un-manually you can put print("\033c")