Learn to Code via Tutorials on Repl.it!

← Back to all posts
Styling Text In Python!
h
JWZ6 (670)

Hello! :)

I hope that u guys r doin' great!

Soooooooooooooooooooo...

Welcome to my Python Styling Text Tutorial

(Idk every single way to style, but this is what I know)

Colorizing

How to Use

For example, if you want your text to look red, you can do:

# This is the code for red, it doesn't have to be a variable
red = "\033[31m"
# This is the code for bold, it doesn't have to be a variable
bold = "\033[1m"
# You can imply red like
print(red + "Your text in red")
# You can also just do
print("\033[31m" + "\033[1m" + "Your text in red and bold")
# Or you can do
print("\033[31mYour text in red")

The output will look like this:

Your text in red
Your text in red and bold
Your text in red

Those just some examples on how to use colorizing.

Color Codes (basic)

These are some of the basic color codes

Gray/Grey: "\033[30m"
Red: "\033[31m"
Lime: "\033[32m"
Orange: "\033[33m"
Blue: "\033[34m"
Purple: "\033[35m"
Light Blue: "\033[36m"
Ghostwhite: "\033[37m"

Btw: Ghostwhite is a darker form of white

That was simple!

Color Codes (light)

These are some of the light color codes

Gray/Grey: "\033[90m"
Red: "\033[91m"
Lime: "\033[92m"
Yellow: "\033[93m"
Light Blue 2: "\033[94m"
Light Purple: "\033[95m"
Cyan: "\033[36m"
White: "\033[37m"

Noice...

Bold, Underline, Italic, Dark, Normal, Reset Codes

Reset: "\033[0m"
Bold: "\033[1m"
Dark: "\033[2m"
Italic: "\033[3m"
Underline: "\033[4m"
Normal: "\033[22m"

Phew!

Dark makes the text look blackish and grey/gray.

Reset resets all decoration.

Normal is just normal Python text.

That's It. KTHXBYE!

Edit: I never saw italic and underline before, so I decided to include them.

THESE ARE ANSI CODES

Comments
hotnewtop
Bookie0 (6297)

What's normal? Dark? Reset? Ghostwhite? You could precise what they are exactly. Since this tutorial is kinda short, you could also try explaining how they work. And you havn't used the word 'ANSI' anywhere...

Also, you can use syntax highlighting in your codeblocks by adding py after the 3 backticks (`):

# This is the code for red, it doesn't have to be a variable
red = "\033[31m"
# This is the code for bold, it doesn't have to be a variable
bold = "\033[1m"
# You can imply red like
print(red + "Your text in red")
# You can also just do
print("\033[31m" + "\033[1m" + "Your text in red and bold")
# Or you can do
print("\033[31mYour text in red")
JWZ6 (670)

@Bookie0 btw sorry i is not knowing ANSI but ill try

Bookie0 (6297)

@JWZ6 well, you're using these ANSI codes for the colors.

JWZ6 (670)

@Bookie0 oh really? nice :) (glad you put the effort into helping others)

Bookie0 (6297)

@JWZ6 uh yeah lol. np :) You can check this wikipedia page to know more about ANSI escape codes if you want, as well as this video

ch1ck3n (2077)

Me and darkdarcool made a PyPI package to help with styling as well:

https://pypi.org/project/ConsoleHelp/

so uh well

use it

JWZ6 (670)

@ch1ck3n did you ACTUALLY create that?

JWZ6 (670)

@ch1ck3n btw my customize thingy is fixed so yeah! no more problems n stuff... https://replit.com/talk/share/A-Little-Text-Editor-I-Created/135398 lol

[deleted]

[deleted]

noice

JWZ6 (670)

@Th3Coder lol np (me remembering your welcome meme song)

Th3Coder (129)

@amasab all hail the 100% totally legitimately real unfake CEO!

[deleted]

@Th3Coder xDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

CodeMaster007 (108)

Nice! Can you also put the code below so its easier to see it in actions! Thanks!