Skip to content
← Back to Community
how do you color your text/print
Profile icon
omegawolf187

made a print but i want it to be a different color

Voters
Profile icon
razvandinis
Profile icon
AmesHenry
Profile icon
AshleyPeng
Profile icon
ErdemYigit2
Profile icon
HudsonKang
Profile icon
mkhethanindaba
Profile icon
RobbieORR
Profile icon
FelipeIrvine
Profile icon
CalebHalfmann
Profile icon
BenjaminHunt4
Comments
hotnewtop
Profile icon
CalebCarlson

TEXT STYLE: CODE


No effect: 0
Bold: 1
Underline: 2
Negative1: 3
Negative2: 5


TEXT COLOR: CODE


Black: 30
Red: 31
Green: 32
Yellow: 33
Blue: 34
Purple: 35
Cyan: 36
White: 37


BACKGROUND COLOR: CODE


Black: 40m
Red: 41m
Green: 42m
Yellow: 43m
Blue: 44m
Purple: 45m
Cyan: 46m
White: 47m


The first thing you do when styling text in python is you start with an escape code. The escape code for this will always be the same.
This is the escape code:
\003[
Next, you put the code for text style:
\003[1
(if you don't care what style you want just use 0)
You will always use a semi-colon to separate your style codes.
Next, you put the code for text color:
\003[1;32
Next, you put the code for what background color you want:
\003[1;32;43m
The above example would show green text, bold, with a background color of yellow.
You add text by just typing directly after the m in the background color code:

print("\033[1;33;44m Charles Robison")

You put the style code directly in the string.

Profile icon
HarveyYalung

how do I change colour comments?

Profile icon
ArjunSS1

Caleb had a very good answer but a simple answer would be to import the colored module where colored.fore contains the different colors so you can do

From colored import fore print(fore.RED + ‘This is red!’) print(‘This is still red!’ + fore.WHITE) print(“Now White!”)
Profile icon
CalebCarlson

@ArjunSS1


I had no idea that even existed XD

Profile icon
ArjunSS1

@CalebCarlson Yea I used to use the whole /0 system but colored is so much easier to use for small color changes

Profile icon
CalebCarlson

@ArjunSS1


I agree(: