Ask coding questions

← Back to all posts
How do you make the output text in Python coloured instead of white?

For example, instead of white, it is red.

Answered by Muffinlavania (1517) [earned 5 cycles]
View Answer
Muffinlavania (1517)

Color codes (yaya)

black = "\033[48;5;232m" 
red = "\033[48;5;124m" 
green = "\033[48;5;34m" 
yellow = "\033[48;5;226m" 
blue = "\033[48;5;21m" 
magenta = "\033[48;5;57m" 
cyan = "\033[48;5;87m" 
bright_black = "\033[48;5;240m" 
bright_red = "\033[48;5;196m" 
bright_green = "\033[48;5;118m" 
bright_yellow = "\033[48;5;228m" 
bright_blue = "\033[48;5;45m" 
bright_magenta = "\033[48;5;92m" 
bright_cyan = "\033[48;5;123m" 
bright_white = "\033[48;5;254m"

then use them like this:

print(red+'Red text yay')
print("still red text")
print(reset+"normal text now")

@Muffinlavania Thank you!


@Muffinlavania So I should put it on the top of the code, right?

Andy_4sberg (50)

@Muffinlavania 'f' strings are faster

bold = '\033[1m'

print(f"{red}Red text!")
Andy_4sberg (50)

@LeShuriken, if you want cleaner code, you can use the colored text module, though I don't recommend it because it has some glitches.


@Andy_4sberg Ok, thanks!


@Muffinlavania I got his when I run the code

I wanted the writing in blue, not highlighted in blue

Muffinlavania (1517)

@LeShuriken the color codes are like this \033[48;5;whateverm, they should be like \033[38;5;whateverm (the 48 is for background colors, the 38 is for foreground colors


@Muffinlavania OHH Ok thanks