Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Dee K
17,815 PointsQuestions 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')?
Thanks
1 Answer

srikanth chavvakula
6,178 PointsHello Kim,
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.
Dee K
17,815 PointsDee K
17,815 PointsHey Srikanth,
Thanks for your in depth answer. That really helped a lot!