Skip to content

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
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App