An easier way to clear a screen while in python is to use Ctrl + L though it works for the shell as well as other programs. Command+K works fine in OSX to clear screen. Shift+Command+K to clear only the scrollback buffer. Subprocess allows you to call “cls” for Shell.
Create a file and copy paste below python program code to clear screen with the output.
from time import sleep
# The screen clear function
# for mac and linux(here, os.name is 'posix')
if os.name == 'posix':
_ = os.system('clear')
# for windows platfrom
_ = os.system('cls')
# print out some text
print("The platform is: ", os.name)
print("big output\n"* 5)
# wait for 5 seconds to clear screen
# now call function we defined above
The platform is: nt
That’s all, I hope this helped you!
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.