-1

I want to add text color while print output. How to do that ?

Example: Print('Hello Everyone.') I want output text Hello Everyone will highlighted red color.

Thanks you!

Chandan
  • 571
  • 4
  • 21
trunghai
  • 3
  • 4

2 Answers2

1

An easy way to do this is to import a color module like colorama or termcolor. This site might be useful: Print Colors in Python terminal. For you code it would be:

from colorama import Fore
print(Fore.RED + 'Hello Everyone') 

or

import sys 
from termcolor import colored, cprint
print(colored('Hello Everyone', 'red'))  # method one
cprint('Hello Everyone', 'red')          # method two
WangGang
  • 533
  • 3
  • 15
0

Try this.

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.OKGREEN + 'Hello Everyone')
krishna
  • 1,029
  • 6
  • 12