Import os
os.system("clear") # Linux - OSX
os.system("cls") # Windows
# There are ANSI Escape Control Characters that can be used to clear the screen
# https://en.wikipedia.org/wiki/ANSI_escape_code#Control_characters
# ^H can be used to move the cursor left most (start line)
# and ^J can be used clear the part of the screen from the cursor to the end of the screen
# together
print("33[H33[J")
import os
# Windows
os.system('cls')
# Linux
os.system('clear')
print(“33[H33[J”)
os.system('cls' if os.name in ('nt', 'dos') else 'clear') #Works for both windows and linux
>>> import os
>>> clear = lambda: os.system('cls')
>>> clear()
from os import system
from sys import platform
clear_screen = lambda: system("cls" if platform == "win32" else "clear")
clear_screen() # will clear the console
# Cross-platform using appropriate commands for Windows and non-Windows