0

Whether it's a module or something I can define in my code, is there a way to change the output text like making it italic or BOLD? Also, are colours a thing?

TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
Elijah D-R
  • 33
  • 2
  • 11

1 Answers1

0

Taking the question @LukeK posted, you can use ANSI escape sequences anywhere in your strings:

print("Roses are \033[31mred\033[0m") # Will make red... red

You can combine them in that way (I hope it's clear enough):

BOLD_AND_RED = "\033[1;31m"

On the other hand, you can find modules that allow simpler (or nicer) ways of doing it, but I prefer writing code with minimal dependencies, so I usually put some global variables and I later concatenate them with my strings:

RED    = "\033[31m"
BOLD   = "\033[1m"
ITALIC = "\033[3m"
RESET  = "\033[0m"

print(BOLD + RED + "ERROR: " + RESET + ITALIC + "blah blah...")

Last note! This escape sequences only work in terminals, and I don't think they work in Windows cmd.

José Miguel
  • 280
  • 3
  • 7