Print Colored Text with Python

Print Colored Text with Python using Colorama

In Python the Colorama module allows us to easily create colored terminal text. In this article, I will take you through a tutorial on how to print Colored Text with Python by using the Colorama module in Python.

What is Colorama in Python?

Using the Colorama module we can print colored text with Python. We can use it and call its built-in variables which are aliases for the desired ANSI codes. This makes our code more readable and works better with Windows command prompts after calling colorama.init() at the start of your script.

Also, Read – 100+ Machine Learning Projects Solved and Explained.

The Colorama module offers three main formatting options: Fore, Back, and Style. These allow us to change the foreground or background text color and style. The colors available for the foreground and background are black, red, green, yellow, blue, magenta, cyan, and white.

Print Colored Text with Python

Traditionally, printing full-colour text to the terminal is accomplished by a series of escape characters on Linux or OS X systems. However, this will not work for Windows operating systems. Now let’s see how to print coloured text with Python using the Colorama module:

print colored text with Python using colorama

It is also possible to change other text properties using ANSI escape characters, for example, if we wanted to make the text darker or lighter. You can learn more about this Python module from here.

I hope you liked this article on how to print colored output with Python by using the Colorama module. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

6 Comments

  1. Unable to see the colored text in IDE/Jupyter.. Any suggestions? Thanks in advance:)

  2. […] an algorithm to create a maze solver with Python programming language. I will make use of the Colorama module in Python here to see a colourful result of the maze […]

  3. does not work in python3 under Wiing ide. did pip istall colorama..says it was done, py script does not print color.

  4. Aman. Got it to work(colorama)… It was the fault of Wing sending print to debug screen, and it does not support colorama.— Switched to letting Wing be my IDE, but I TEST/RUN in … shell ,or TERMINAL! = ok colors !!!Thanks for the answer and concern You do good work….no excellent work..

Leave a Reply

Data Science | Machine Learning | Python | C++ | Coding | Programming | JavaScript