Python Program to Print Colored Text to the Terminal – 2024

Hey guys, in this blog we will see a Python Program to Print Colored Text to the Terminal.

Table of Contents

Example 1: Using ANSI escape sequences

print('\x1b[38;2;251;32;86m' + 'Machine Learning Projects' + '\x1b[0m')

Output

Machine Learning Projects
  • Here we have used the above code to print our colored text.
  • Here the main thing to notice is the RGB code we have provided in the code.
  • The RGB code I provided is (251,32,86).

Example 2: Using the python module termcolor

from termcolor import colored

print(colored('Machine Learning Projects', 'red',))

Output

Machine Learning Projects

For more information regarding the ANSI escape code, you can refer to the ANSI escape code.

Check out our other python programming examples

Leave a Reply

Your email address will not be published. Required fields are marked *