Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

How do you clear the console in Python?

saltyChipps
saltyChipps

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

2 years ago

Voters

Comments

TopNew
2

Solution

Do:

import os os.system("clear")
2 years ago
2

@saltyChipps

no problem! 😁

2 years ago
1
Coder100
Coder100
import os os.system("clear")

copy and paste that each time you want to clear.

2 years ago
1
henryeth
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!

2 years ago
Load more