0

How to color the text output in python3?

I have not learnt how to give color to the text output.

19th Sep 2019, 5:34 AM
Piush K Sangma
Piush K Sangma - avatar
3 odpowiedzi
+ 3
Really? As far as I know the console based text can't be coloured unless you are on certain IDEs.
19th Sep 2019, 6:51 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Not my code. To change the color you need escape codes. Heres an example class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' print( bcolors.WARNING + "Warning! Continue?" + bcolors.ENDC ) Another solution could be this I think (not tried) from termcolor import colored print(colored('hello', 'red'), colored('world', 'green'))
19th Sep 2019, 6:16 AM
Trigger
Trigger - avatar