Skip to content
Sign upLog in
← Back to Community

How do you clear the console in Python?

Profile icon
saltyChipps

I'm trying to clear the console every time the code is run, but I don't know how.

Voters
Profile icon
saltyChipps
Comments
hotnewtop
Profile icon
[deleted]

Solution

Do:

import os os.system("clear")
Profile icon
saltyChipps

Thanks!

Profile icon
[deleted]

@saltyChipps

no problem! 😁

Profile icon
Coder100
import os os.system("clear")

copy and paste that each time you want to clear.

Profile icon
henryeth

Nice basic option to answer this question, there is a handy module "os" that contains a function that will work: system(). Here is the syntax you want:

from os import system clear = lambda: system("clear") # Now you can do it at any time by simply calling: clear()

Hope this helped!