lucky
0
Q:

how to add colour to text python

def colored(r, g, b, text):
    return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
  
text = 'Hello, World'
colored_text = colored(255, 0, 0, text)
print(colored_text)

#or

print(colored(255, 0, 0, 'Hello, World'))
2
"\033[1;32;40m Bright Green"
#\033[  Escape code, this is always the same
#1 = Style, 1 for normal.
#32 = Text colour, 32 for bright green.
#40m = Background colour, 40 is for black.
"\033[1;30;40m Black"
"\033[1;31;40m Red"
"\033[1;32;40m Bright Green"
"\033[1;33;40m Yellow"
"\033[1;34;40m Blue"
"\033[1;35;40m Purple"
"\033[1;36;40m Cyan"
"\033[1;37;40m White"
2

New to Communities?

Join the community