How do i change the color of text in python or can i not

You can

In addition:

\x1b[38;2;{r};{g};{b} works for foreground


Use ANSI color codes. I have some at the top of this Py file.


Try looking at termcolor, it is a useful library for coloring text in the terminal.


You can copy and paste the code from python terminal colors · GitHub (I recommend bookmarking it)

Here’s how you can use them:

BLACK   = '\033[30m'
RED     = '\033[31m'
GREEN   = '\033[32m'
YELLOW  = '\033[33m'
BLUE    = '\033[34m'
MAGENTA = '\033[35m'
CYAN    = '\033[36m'
WHITE   = '\033[37m'
RESET   = '\033[39m'

print(f'Hello {BLUE}world!{RESET}')
1 Like

thank you this is the most helpfull responce on this post

1 Like

No problem. Welcome to the community BTW =D

1 Like

did you just say you’re gonna cheat?

1 Like

lol best answer is no answer I guess @FenixPenning , but seriously, could you please not cheat/elaborate?

Ok but can you elaborate?

1 Like

Ok um that’s not an… explanation

it was a joke ok im just trying to have a little fun because im exited my code worked rn

1 Like

The last time I saw somebody say this was for help for school they got in trouble with the mods because it people use Replit to cheat, it gets banned in schools. So be careful what you say.

1 Like

ooohhh, lol sorry about bothering you

@bigminiboss’s is very good, but you can also do

import colorama

and then you can do things like:

print(f"{colorama.Fore.BLUE}This text is blue!")

This will output the text in blue. There are also many other Fore colors, the colorama documentation has them all: Documentation

1 Like

I wouldn’t use colorama since it has some disadvantages I can’t remember off the top of my head but yes that works

1 Like