Ask coding questions

← Back to all posts
Is there a command to clear the screen in python?
MesyetiIsTaken (56)

Out of curiosity is there a command to clear the screen in python?

Answered by Bookie0 (6310) [earned 5 cycles]
View Answer
Bookie0 (6310)

But first import os
Also what I like to do is put that in a function that I call clear():

def clear():

So that it’s easier to call it

Kopamed (193)

Yes. This is the best one. The others take wayyyy to long to work so here it is:

import time
def cler():

print("I will be gone soon")
CodingCactus (4367)

Yes, just print("\033[2J\033[H", end="")

CodingCactus (4367)

you can put in function if you want:

def clear():
  print("\033[2J\033[H", end="")
CodingCactus (4367)

@MesyetiIsTaken no problem, it is nice because there are no needs for imports and also very few lines

Lord_Poseidon (170)

Specific to, use the package manager to install the replit package and call replit.clear() to clear the screen.

Mark as answer if this helps!

ApoorvAgrawal (51)

@Lord_Poseidon If I needed to clear the screen, I personaly wouldn't use replit.clear(), because if you want to download the code and run it on off your browser, it wouldn't work and you would have to replace it with either

import os



if you are on windows

Lord_Poseidon (170)

@ApoorvAgrawal still, it is platform specific. I get your point though.