Define color like this:

W  = '\033[0m'  # white (normal)
R  = '\033[31m' # red
G  = '\033[32m' # green
O  = '\033[33m' # orange
B  = '\033[34m' # blue
P  = '\033[35m' # purple

print(R+"hello how are you"+W)

Demo:

see all color codes here:Color Codes

Answer from Hackaholic on Stack Overflow
🌐
Sentry
sentry.io › sentry answers › python › print colored text to terminal with python
Print colored text to terminal with Python | Sentry
How can I print colored text to the terminal in Python? On most platforms, terminal colors are produced using ANSI escape sequences. We can use these directly, or through a Python library. Terminal output can be colored by surrounding it with ANSI escape sequences: BLACK = '\033[30m' RED = '\033[31m' GREEN = '\033[32m' YELLOW = '\033[33m' # orange on some systems BLUE = '\033[34m' MAGENTA = '\033[35m' CYAN = '\033[36m' LIGHT_GRAY = '\033[37m' DARK_GRAY = '\033[90m' BRIGHT_RED = '\033[91m' BRIGHT_GREEN = '\033[92m' BRIGHT_YELLOW = '\033[93m' BRIGHT_BLUE = '\033[94m' BRIGHT_MAGENTA = '\033[95m'
🌐
GeeksforGeeks
geeksforgeeks.org › print-colors-python-terminal
Print Colors in Python terminal - GeeksforGeeks
June 27, 2022 - The most common way to print colored text is by printing ANSI escape sequences directly. This can be delivered in different formats such as: ... We can build functions to call particular color named functions to execute the relevant ANSI Escape Sequence. The below is Python program to print colored text and background
Top answer
1 of 16
3045

This somewhat depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here's some Python code from the Blender build scripts:

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKCYAN = '\033[96m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

To use code like this, you can do something like:

print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC)

Or, with Python 3.6+:

print(f"{bcolors.WARNING}Warning: No active frommets remain. Continue?{bcolors.ENDC}")

This will work on unixes including OS X, Linux and Windows (provided you use ANSICON, or in Windows 10 provided you enable VT100 emulation). There are ANSI codes for setting the color, moving the cursor, and more.

If you are going to get complicated with this (and it sounds like you are if you are writing a game), you should look into the "curses" module, which handles a lot of the complicated parts of this for you. The Python Curses HowTO is a good introduction.

If you are not using extended ASCII (i.e., not on a PC), you are stuck with the ASCII characters below 127, and '#' or '@' is probably your best bet for a block. If you can ensure your terminal is using a IBM extended ASCII character set, you have many more options. Characters 176, 177, 178 and 219 are the "block characters".

Some modern text-based programs, such as "Dwarf Fortress", emulate text mode in a graphical mode, and use images of the classic PC font. You can find some of these bitmaps that you can use on the Dwarf Fortress Wiki see (user-made tilesets).

The Text Mode Demo Contest has more resources for doing graphics in text mode.

2 of 16
1220

There is also the Python termcolor module. Usage is pretty simple:

from termcolor import colored

print(colored('hello', 'red'), colored('world', 'green'))

It may not be sophisticated enough, however, for game programming and the "colored blocks" that you want to do...

To get the ANSI codes working on windows, first run

os.system('color')
🌐
Stack Abuse
stackabuse.com › how-to-print-colored-text-in-python
How to Print Colored Text in Python
February 27, 2023 - We need a reset point to stop the printing of colors. This can be done by appending \033[0;0m to the string as: ... The \033[0;0m code represents a reset pattern that returns the terminal back to its original color scheme. This will provide the following output: Looks much better. Colorama is a Python package that provides methods to print colored text in Python.
🌐
Python
bugs.python.org › issue21029
Issue 21029: IDLE mis-coloring "print" - Python tracker
March 22, 2014 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/65228
🌐
YouTube
youtube.com › tech with tim
How To Print Colored Text in Python (Colorama Tutorial) - YouTube
In this video I'll be showing how to print colored text in python. This method will show you how to output colored text from python in windows, mac and linux...
Published: December 21, 2020
Views: 128K
🌐
Python
mail.python.org › pipermail › tutor › 2011-January › 081294.html
[Tutor] color of "print" function
January 15, 2011 - However, occasionally, it's purple ... this happens, I can change it back to orange by manipulating the spacing (adding an empty line, and then deleting it seems to do the trick). Thanks. Previous message: [Tutor] color of "print" function...
🌐
PyPI
pypi.org › project › python-print-color
python-print-color · PyPI
September 10, 2023 - # Example 4: Print RGB colored ... and a custom foreground color (e.g., orange) print_color_rgb("Italic text with orange foreground", foreground=(255, 165, 0), styles=["italic"]) # Example 6: Print RGB colored text with underline ...
Find elsewhere
🌐
Ethika
ethika.com › s › UMM1338 › python-embossed-orange-mid
MENS MID Embossed Python - Orange | Ethika
Buy the MENS MID Embossed Python - Orange: Shorter Mid Length Fit, No Pull-Down, No Gathering, Specialty Embossed Print Design, Soft 4-Way Stretch Fabric, High-Quality Jacquard Waistband, Specialty Embossed Print Design, 82% Polyester 18% Spandex
🌐
University of North Carolina
cs.unc.edu › ~lin › COMP089H › PAPERS › Intro2Python.pdf pdf
Introduction to Python COMP 089H Fall 2015 Written by Tanya Amert
In this example, we introduce a few important concepts. Syntax Highlighting: keywords, strings, shell output · First, note that IDLE colors the different parts of this code differently. This is called syntax highlighting. The word “print” is orange because Python recognizes it as a keyword.
🌐
Reddit
reddit.com › r/learnpython › how do i make the output text orange using ansi code?
r/learnpython on Reddit: How do I make the output text orange using ANSI code?
June 27, 2018 -

Here are a few of the colors I know:

purple = "\033[95m"
cyan = "\033[96m"
darkcyan = "\033[36m"
blue = "\033[94m"
green = "\033[92m"
yellow = "\033[93m"
red = "\033[91m"
magenta = "\033[35m"
white = "\033[37m"
black = "\033[30m"

I cant figure out what the code is for orange.

Thanks in advance!

🌐
Readthedocs
orange3.readthedocs.io › projects › orange-visual-programming › en › latest › widgets › data › pythonscript.html
Python Script — Orange Visual Programming 3 documentation
Pressing Run executes the script (keyboard shortcut "Ctrl+R"). Any script output (from print) is captured and displayed in the Console box. Python Script widget is intended to extend functionalities for advanced users. Classes from Orange library are described in the documentation.
🌐
YouTube
youtube.com › shorts › siJ2g_GOpmA
Print In Color In Python #python #code #programming - YouTube
In this python tutorial, I show you how to print in color in your terminal! We talk about how to use ANSI codes to change the color of your terminal output! ...
Published: July 30, 2024
🌐
AskPython
askpython.com › python › examples › print-colored-text-to-the-terminal-in-python
Print Colored Text to the Terminal in Python - AskPython
February 23, 2023 - There are Python modules especially suited for displaying colored text, ANSI is a no-dependency method used for color codes. ANSI escape sequence is in-band signaling to control locations of cursors and colors, to style the font, and much more. Let us take a look at how we can use ANSI to print the colored text to the console.
🌐
Medium
vascosim.medium.com › pythonic-aesthetics-enhancing-terminal-readability-with-color-52f6244e2e30
How to Print Colored Text in Python | Medium
January 23, 2024 - The ‘print’ function in Python is fundamental for displaying information in the console.
🌐
Medium
medium.com › ai-does-it-better › print-colored-text-in-python-enhance-terminal-output-b90aede058c8
Print Colored Text in Python — Using colorama-termcolor | by Doug Creates | AI Does It Better | Medium
December 28, 2024 - Printing colored text in Python involves using third-party libraries like colorama to manipulate terminal output, enabling developers to…
🌐
Towards Data Science
towardsdatascience.com › home › data science › python - print colored text with ease
Python - Print colored text with ease | Towards Data Science
October 18, 2021 - Py-console is a package that I've created that makes printing colors super-easy. It emulates JavaScripts well-known methods likeconsole.log, console.warn, console.error etc. It also adds some more functionalities. Want to create your own Python package? → check out [this article](https://mikehuls.medium.com/create-your-custom-python-package-that-you-can-pip-install-from-your-git-repository-f90465867893) for instructions.
🌐
YouTube
youtube.com › watch
Print Colorful Text in Python – Easy Terminal Styling with Colorama - YouTube
Print Colorful Text in Python - Beautiful Output Using Python Colorama▬▬▬▬▬▬▬▬▬▬▬▬📌 Timestamps:00:00 - intro00:13 - What Is Colorama in Python? (Fore & Back...
Published: May 21, 2025