How to print to console in color? [duplicate]
This question already has answers here :
How to print colored text in Python? (49 answers)
Closed 3 months ago.
How to print in color using python print. For example
print('This should be red')
print('This should be green')
Now everything is white text on black background. I use ubuntu, if it helps.
-
Define color like this:
W = '\033[0m' # white (normal) R = '\033[31m' # red G = '\033[32m' # green O = '\033[33m' # orange B = '\033[34m' # blue P = '\033[35m' # purple print(R+"hello how are you"+W)
Demo:
see all color codes here:Color
Codes