Learn to Code via Tutorials on Repl.it!

← Back to all posts
🐍 Python Text Styles 🐍 [UPDATED!]
SilvermoonCat (457)

Python Text Styles!

Today we're going to learn:

  • italic, bold, underline
  • all the colors (I know)

Alright! Let's begin:

print("Welcome to python text style tutorials.")

How do we make that text prettier?

First, let's add color

To add color, you can import it. However, a fancier way can be used (I prefer this way).

print("\033[0;36mblue text :D")


So, add the \033[ first.
After that, add either 0,1,2,3 or 4.
0: Normal text
1: Bold
2: Pale
3: Italic
4: Underline

psst: TIPS!
If you are doing let's say pale then bold,
Make sure to do \033[0;1;39m (You can change
the color, of course) But please remember to
clarify it's not pale anymore-
With the 0. Or else... dun dun dun

Alright. Now add that, and we have

print("\033[1;Colored text")

You run the code.

Er, it's not working

Right. We must add the color. Go to main.py to see more, but you can also stay here.
Red: 31
Orange: 33
Yellow: 93
Green: 32
Cyan: 36
My favorte, light blue: 94
Blue: 34
Purple: 35
Gray: 37
White: 39

print("\033[1;36Colored text)

Still not working.

Add a m after the number for your color.
e.g. "\033[1;36mColored text"


also: Here’s a easy shortcut!
You can list them out: e.g.
cyan = "\033[1;36m" white = "\033[1;39m" reset = "\033[0m"
then use them like:
print(cyan + "Cyan text" + reset)
Should be working now, have fun using the colors! If you discover any new colors or have any questions, comment here.

Bookie0 (6359)

umm that is very annoying use variables that hold the ANSI escape codes lol..

ZhongRietveld (32)

Can you also use RGB-colors for printing a string?

SilvermoonCat (457)

@ZhongRietveld I don’t think so but I’m not like a python color expert or smth so maybe you could search it up? I really wish they would allow RGB colors or hex codes. If you find anything interesting you can tell me!!

ZhongRietveld (32)

@SilvermoonCat I had search it on the internet and guess what? You can RGB color print!

print("\033[38;2;R;G;BmHello World")

SilvermoonCat (457)

@ZhongRietveld wow, cool! I’ll try it sometime :D


how do you do yellow

SilvermoonCat (457)

@JULIODIAZ1 ooh I should add that...

print("\033[1;93mThis is yellow text")
#bolded because of the 1
SenatorBinks (16)

Nice job, this is pretty helpful

LuckyOreos (203)

I already know most of these but it’s one of the things I always suggest to people and it’s just what every python repl needs!!! It’s not toooooo coding related but nice job!!!

SilvermoonCat (457)

thanks :D Since I'm not good at codes so i have to do this stuff--

LuckyOreos (203)

@SilvermoonCat It’s alright you still put in a lot of effort