Ask coding questions

← Back to all posts
How to Format Text in Python
PradyumnaChaudh (1)

Hello all .. Please someone tell me atleast 5 ways to format text in Python. Thanks 😊

Comments
hotnewtop
Coder100 (18873)

hi! What do you mean by formatting text?

PradyumnaChaudh (1)

@Coder100 Formatting Text means decorating/styling text like how you do in MS Word . Example - Bold , Italic , Change Colour and Size , etc .

rediar (524)

If this is a homework question, please do not ask us, if it isn’t, I’m sorry for thinking it is.

PradyumnaChaudh (1)

@rediar It isn't a homework question . It was my Curiosity . I'm Smart enough To Do HW by my own .

rediar (524)

@PradyumnaChaudh ok, awesome then, it just kinda sounded like one, I apologize.

Muffinlavania (1527)

There are not many ways to format text in python like you can do in html.... But in python(with turtle) you can style text that you draw. In regular python you can make your text bold, underlined, different colors, and more!
Cool Way to print out text here!

Bold

from colorama import Style
print(Style.BRIGHT+"This is Bold")
#Can also be dim/opposite of bold
print(Style.DIM+"This is Dim")
#Reset the style
print(Style.RESET_ALL+"This is normal")

Underline

print("\u0332".join("Underlined text goes here")

Different colors

from colorama import Fore
print(Fore.RED+"Red text")
print(Fore.BLUE+"Blue text")
Can be any of these colors:
Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
#Reset changes back to white
CodeLongAndPros (1631)

String concat: foo + ' ' + bar
.format(): '{} {}'.format(foo, bar)
F-String: f"{foo} {bar}"