Welcome to the Treehouse Community
Looking to learn something new?
Dee K17,815 Points
Questions about the clear() function.
def clear (): if os.name == 'nt': os.system('cls') else: os.system('clear')
In this function, I am still confused about what os.system('cls') does? I know that if my operating system is a windows (which it is) then the os.system('cls') occurs.
What exactly is the purpose of os.system('cls')?
srikanth chavvakula6,178 Points
The purpose of os.system() is to invoke any external program (all exe files that are generally available in system32 folder) that you can generally open via the "windows--> Run" dialog box. So, in simple terms the command uses the windows subshell (command prompt) to invoke an external program. For ex: try the command "os.system('notepad') which will actually invoke the notepad on windows, which is very similar to opening notepad via the command prompt. Also try os.system('Calc') which will open the calculator in windows.
By the way, "cls" is a command that is used to "CLEAR SCREEN" on the windows command prompt.
Hope this is helpful.