← Go Back
On Windows:
On Linux or macOS:
You can create a simple cross-platform function by checking the value of
How to Clear the Terminal/Console/Screen
To clear the console in Python, use the standardos.system()
function.On Windows:
import os
os.system("cls")
On Linux or macOS:
import os
os.system("clear")
You can create a simple cross-platform function by checking the value of
os.name
:import os
def clear_console():
"""
Clear the console on Windows, Linux and macOS.
"""
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
clear_console()
🐍 You might also find interesting: