In this tutorial, we will learn How to print colored text to the terminal where each color has its own color code for which we give the color to understand it there is a list below with most of the colors along with their code which will result into that particular color let’s look at those colors and their codes.
class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKCYAN = '\033[96m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m'
Here the code for each possible code is given which you can follow as per their own requirements.
Color of Text On Terminal
Using Color Coding
For making the text on the terminal colored there is a specific code for color and for implementing it both so now let’s explore them and try to learn them and implement them in our programs.
print("\033[1;31;40m Red Text \033[0m")
Here we have used a code for a particular color.
Using Some Module
We also have another way to implement the same which is using the inbuilt library and importing the package for the same in that case we do not have to write any code for coloring the text we provide the name of the color and the task would be done.
For the same you may follow the code given below and implement it along with learning
from termcolor import colored print(colored("Red Text", "red"))
In the above code, the output will be “Red Text” written in red in the terminal which is nothing but colored output as we want.
Learn more about How to Print Colored Text To The Terminal at Colored text on the terminal in python on Stack Flow.
Also, visit Python Tutorial – How to color the text on the terminal | Python Programs Examples. and learn about Python. and for learning different programming languages and solving problems as per our requirements. and learning concepts related to programming.