Many program types have students interacting with their code through the console in the CodeHS editor. Here are a few features students can use in their code to control output in the console:

Clearing the Output

There are a few techniques for clearing the output of the console. The first is to print a special character sequence (ANSI Escape sequence) which terminals know to interpret as a command to clear text.

For Python:

Use one of the two lines:


These will clear anything printed before they were printed.

You can also import the os module to call the clear function, like this:

import os


Which will have the same effect.

For Java:



Check out this tutorial for more information on clearing the console.

Use ANSI Escape Codes to Color and Highlight Text

It's also possible to use the ANSI codes to color and highlight text in the console. Just include the correct escape code when printing a string:

print('\033[92mHello world\033[0m')


print('\033[93m' + 'Hello world' + '\033[0m')

Check out this example program to see this in action.

Click below for a more detailed explanation on ANSI colors in the terminal:

Still have questions? Contact our team at to learn more!

Did this answer your question?