How to clear screen (console) in Python3
There are three ways to clear screen/console in Python3:
using print
print("\033c", end='')
using os
from os import system, name
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
clear()
using os and call
import os
from subprocess import call
def clear():
_ = call('clear' if os.name == 'posix' else 'cls')
clear()
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here