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, is 'posix')
        _ = system('clear')


using os and call

import os
from subprocess import call
def clear():
    _ = call('clear' if == 'posix' else 'cls')


  1. License under CC BY-NC 4.0
  2. Copyright issue feedback, 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