Sometimes, we want to clear the interpreter console with Python.
In this article, we’ll look at how to clear the interpreter console with Python.
How to clear the interpreter console with Python?
To clear the interpreter console with Python, we can run the command to clear the screen for the operating system.
For instance, we write
import os
clear = lambda: os.system('cls')
clear()
to create the clear
function that runs the cls command on Windows with os.system('cls')
.
Likewise, we can run the clear command to clear the screen on Linux by writing
import os
clear = lambda: os.system('clear')
clear()
Conclusion
To clear the interpreter console with Python, we can run the command to clear the screen for the operating system.