How to clear screen in python | Sololearn: Learn to code for FREE!
Nowy kurs! Każdy programista powinien nauczyć się Generative AI!
Wypróbuj darmową lekcję
+ 1

How to clear screen in python

Like in c++ we use clrscr()

1st Nov 2020, 12:20 PM
Gaurav
Gaurav - avatar
5 odpowiedzi
+ 6
I don't think there is any cls() function in C/C++ either. The only way to clear the screen I know is to invoke command processor using system() function and pass the clearning screen command as argument according the the shell that system is using.{ similar would be for python }
1st Nov 2020, 12:24 PM
Arsenic
Arsenic - avatar
+ 6
This is not valid in any morden standard C/C++ compiler. The stuff you are using here is 30 years old and was ment to be used for MS-DOS copilers only.
1st Nov 2020, 12:32 PM
Arsenic
Arsenic - avatar
+ 5
Gaurav Yadav first of all, the lines of code you just mentioned use the conio.h header file, which is not avaiable anymore with the c++ compilers. Secondly, adding to Arsenic 's answer, the "clear" command is for linux and macOS and "cls" command is for Windows. So to clear screen, you will import the os module, and will do os.system("clear") in linux and macOS and os.system("cls") in Windows.
1st Nov 2020, 12:33 PM
XXX
XXX - avatar
+ 2
from os import system system ('cls') #on win, use third line on Linux system ('clear')
5th Nov 2020, 9:35 PM
abdulconsole
abdulconsole - avatar
0
My mistake #include <conio.h> clrscr()
1st Nov 2020, 12:28 PM
Gaurav
Gaurav - avatar