How do I print colored text to the terminal?
You can use the termcolor
module to print colored text to the terminal in Python. Here is an example:
from termcolor import colored
print(colored('Hello, World!', 'red'))
This will print the text Hello, World!
in red.
You can also use the colorama
module, which works on Windows and provides support for ANSI escape sequences:
from colorama import Fore
print(Fore.RED + 'Hello, World!')
Both termcolor
and colorama
support a wide range of colors and formatting options. You can find more detailed documentation for these modules online.