w3resource

Python: Clear the screen or terminal

Python Basic: Exercise-99 with Solution

Write a Python program to clear the screen or terminal.

Sample Solution:-

Python Code:

import os
import time
# for windows
# os.system('cls')
os.system("ls")
time.sleep(2)
# Ubuntu version 10.10
os.system('clear')

Flowchart:

Flowchart: Clear the screen or terminal.

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to get the system time.
Next: Write a Python program to get the name of the host on which the routine is running.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Try-catch-else construct:

try:
  foo() 
except Exception: 
  print("Exception occured")
else:
  print("Exception didnt occur")
finally:
  print("Always gets here")