Last updated: Apr 11, 2024
Reading time·3 min

To clear the terminal in PyCharm:
Focus the terminal Window (you can open it by clicking on Terminal in the bottom bar).
Depending on your operating system, you will have to type cls (Windows) or
clear (macOS and Linux).

For example, suppose we have the following main.py file.
site = 'bobbyhadz.com' print(site)
You can click on the Terminal button in the bottom bar to open the terminal and issue the following command.
python main.py # Or python3 python3 main.py # Or py (Windows) py main.py
The command runs the main.py file using the python interpreter.
To clear the terminal, use the cls (Windows) or clear command macOS or
Linux.
# macOS and Linux clear # Windows cls

Try using either command to verify which one works for your shell type.
On macOS and Linux, you can also clear the terminal by pressing Ctrl + L.
You can also clear the PyCharm terminal by using the Clear Buffer command:

To clear the console in PyCharm:

Make sure to right-click in the upper part of your Python console window (above the last line).
If you right-click below the last line, the Clear All command is not shown.
You can also set a custom keyboard shortcut for the Clear All command:
Ctrl + L.
If you want to clear the console in your Python script, you can print N newline characters.
site = 'bobbyhadz.com' print(site) print('\n' * 100)

When the multiplication operator is used with a string and an integer, the string gets repeated N times.
We used the operator to print 100 newline characters to clear the console.
There is also a Clear all button you can click to clear the console.

As shown in the screenshot, the button has a bin icon and is located in the left sidebar.
You can also clear the screen by using the os module.
import os print('bobbyhadz.com') def clear_screen(): os.system('cls' if os.name == 'nt' else 'clear') clear_screen()
If the operating system is Windows, then os.name will be set to nt.
If we are on Windows, we use the cls command.
If the operating system is not Windows, we use the clear command.
You can call the clear_screen() function to clear the screen.
You can learn more about the related topics by checking out the following tutorials: