How to clear screen | Sololearn: Learn to code for FREE!


How to clear screen

I'm writing a program to simulate a page to create an account and log in. (check out on: I've searched for a function/statement to clear the screen everytime I change from "create account page" to "log in page", but I didn't find anything that worked. I tried: def clear(): os.system('cls') but I failed. So, as a temporary solution, I printed 100 new lines to have the same effect. I wonder, is there any other way to do this? Thanks in advance. PS: check out my other codes if you like ;)

3/31/2017 4:52:56 PM


9 Answers

New Answer


@David Najafi I tried this: >>> import os >>> clear = lambda: os.system('cls') >>> clear() but a cmd prompt poped up and vanished instantly, but nothing changed on my program I also tried on linux, replacing 'cls' by 'clear' but didn't work either


@David Najafi I tried on IDLE and pycharm but didn't worked


@David Najafi I work with Windows and I used import. Still, didn't work


The playground of SoloLearn does not support some functions. Like OS functions. Or httpservice functions, for php and other languages. And c++ in SOLOLEARN does not support some header files like Windows.h


For Windows DON'T FORGET THE IMPORT import os os.system("cls") For OS X, you can use subprocess module and call 'cls' from shell: import subprocess as sp'cls',shell=True) To prevent '0' from showing on top of the window, replace the 2nd line with: tmp ='cls',shell=True) For linux, you must replace cls command with clear tmp ='clear',shell=True)


Call it like this >>> import os >>> clear = lambda: os.system('cls') >>> clear()


try assigning os.system to a variable so it doesn't return 0


If you are writing your code on Android, which is based on Linux, then use the following - import os , then os.system("clear")


import os os.system('cls')