How to clear the Terminal and Console in PyCharm

avatar
Borislav Hadzhiev

Last updated: Apr 11, 2024
3 min

banner

# Table of Contents

  1. How to clear the Terminal in PyCharm
  2. How to clear the Console in PyCharm

# How to clear the Terminal in PyCharm

To clear the terminal in PyCharm:

  1. Focus the terminal Window (you can open it by clicking on Terminal in the bottom bar).

  2. Depending on your operating system, you will have to type cls (Windows) or clear (macOS and Linux).

issue clear command to clear terminal

For example, suppose we have the following main.py file.

main.py
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.

shell
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.

shell
# macOS and Linux clear # Windows cls

clear pycharm terminal

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:

  1. Right-click in the terminal window.
  2. Select Clear Buffer.

clear terminal by issuing clear buffer command

# How to clear the Console in PyCharm

To clear the console in PyCharm:

  1. Right-click in the console window.
  2. Select Clear All.

clear 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:

  1. Click on File in the top menu and then select Settings.
  2. Click on Keymap in the left sidebar.
  3. Type clear all in the search field.
  4. double click the Clear All command and select Add Keyboard Shortcut.
  5. Set your preferred keyboard shortcut for the command, e.g. Ctrl + L.
  6. Press OK.

set keyboard shortcut for clear all command

If you want to clear the console in your Python script, you can print N newline characters.

main.py
site = 'bobbyhadz.com' print(site) print('\n' * 100)

print n newline characters to clear console in pycharm

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.

click on clear all button

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.

main.py
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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.