Skip to content
Sign upLog in
← Back to Community

how to clear screen

Profile icon
jmbeaner

Does anyone know how to clear the screen during the code?
a clear command would be very useful to my program and I don't know one.

Voters
Profile icon
Meand5
Profile icon
TharinduN
Profile icon
AliyaWomack
Profile icon
gatoo
Profile icon
EthanJohnson24
Profile icon
PriyaKarthikeya
Profile icon
WilliamLoebker
Profile icon
cdCreepArghhh
Profile icon
MichelleOvalle
Profile icon
JDarnley
Comments
hotnewtop
Profile icon
hyperupcall

hey!

because you are using python, it is pretty easy to do this

at the top of your file

import replit

to clear the screen, call the clear function

replit.clear()

if you want to see this in action, i forked a repl (credit to

@jamiebally
) here

hope i could help :P

Profile icon
etian

@eankeen
do you know how to do this in c++? :)

Profile icon
hyperupcall

@etian
i dont believe the usual way peopls use to clear the screen in c++ work in repl (i havent actually tried it myself, this is what i heard). this is why you have to import the replit module in python - i dont think there is a similar thing for c++ :P

Profile icon
HackermonDev

@eankeen
In python you can also import system and do system("cls") and it should clear the console

Profile icon
rkel524

@etian
"clear" works now

Profile icon
etian

@eankeen
alright thanks anyway

Profile icon
FourtyCoder

I know a very simple way.
from time import sleep
import os

def cls():
os.system('cls' if os.name=='nt' else 'clear')

print('Hello, World!')
sleep(2.5)
cls()
print('Nice to meet you!')
#This is python way

Profile icon
[deleted]

What about in Python

Profile icon
theangryepicbanana

What language are you using?

Profile icon
jmbeaner

@theangryepicbanana
I am using python... I should have specified that. My bad

Profile icon
theangryepicbanana

@jmbeaner
try print("\x1b[2J\x1b[H", end="")