Take the 2-minute tour ×

How to print bold text in python?

for example:

print "hello"

what's the code that enables the text "hello" to be displayed in bold?


share|improve this question
duplicate of color text in terminal aplications in unix . Lots of links in the answers. That answer is in C, but easily translated to Python. –  Joe Jan 19 '12 at 10:07
Which terminal are you using? Are you on Unix or Windows? –  Sjoerd Jan 19 '12 at 10:08
i'm using safari. Just found out i can use HTML tags in python. –  user1140210 Jan 19 '12 at 11:01
add comment

9 Answers

Use this:

print '\033[1m' + 'Hello'

And to change back to normal:

print '\033[0m'

This page is a good reference for printing in colors and font-weights. Go to the section that says 'Set graphics mode:'

And note this won't work on all operating systems but you don't need any modules.

share|improve this answer
add comment
class color:
   PURPLE = '\033[95m'
   CYAN = '\033[96m'
   DARKCYAN = '\033[36m'
   BLUE = '\033[94m'
   GREEN = '\033[92m'
   YELLOW = '\033[93m'
   RED = '\033[91m'
   BOLD = '\033[1m'
   UNDERLINE = '\033[4m'
   END = '\033[0m'

print color.BOLD + 'Hello World !' + color.END
share|improve this answer
Personally I find this to be the most helpful answer. Usage here: stackoverflow.com/questions/287871/… –  yourfavoriteprotein Aug 21 '13 at 5:37
add comment

There is a very useful module for formatting text (bold, underline, colors..) in Python. It uses curses lib but it's very straight-forward to use.

An example:

from terminal import render
print render('%(BG_YELLOW)s%(RED)s%(BOLD)sHey this is a test%(NORMAL)s')
print render('%(BG_GREEN)s%(RED)s%(UNDERLINE)sAnother test%(NORMAL)s')


I wrote a simple module named colors.py to make this a little more pythonic:

import colors

with colors.pretty_output(colors.BOLD, colors.FG_RED) as out:
    out.write("This is a bold red text")

with colors.pretty_output(colors.BG_GREEN) as out:
    out.write("This output have a green background but you " + 
               colors.BOLD + colors.FG_RED + "can" + colors.END + " mix styles")
share|improve this answer
ImportError: No module named terminal ImportError: No module named render Actually this is the only site I could find about "terminal" module. Please elaborate. –  minerals May 14 '13 at 18:09
The above link used to contain the terminal module, but they have redirect the page. Here is the code cached by google. –  Diego Navarro May 15 '13 at 10:11
Anyways, I have made my own python module to solve this, check it out @minerals ;-) –  Diego Navarro May 15 '13 at 13:45
thanks for the info –  minerals May 17 '13 at 10:44
add comment

This depends if you're using linux/unix:

>>> start = "\033[1m"
>>> end = "\033[0;0m"
>>> print "The" + start + "text" + end + " is bold."
The text is bold.

The word text should be bold.

share|improve this answer
add comment

Check out colorama. It doesn't necessarily help with bolding... but you can do colorized output on both Windows and Linux, and control the brightness:

from colorama import *
print Fore.RED + 'some red text'
print Style.BRIGHT + Fore.RED + 'some bright red text'
share|improve this answer
add comment

In straight-up computer programming, there is no such thing as "printing bold text". Let's back up a bit and understand that your text is a string of bytes and bytes are just bundles of bits. To the computer, here's your "hello" text, in binary.


Each one or zero is a bit. Every eight bits is a byte. Every byte is, in a string like that in Python 2.x, one letter/number/punctuation item (called a character). So for example:

01101000 01100101 01101100 01101100 01101111
h        e        l        l        o

The computer translates those bits into letters, but in a traditional string (called an ASCII string), there is nothing to indicate bold text. In a Unicode string, which works a little differently, the computer can support international language characters, like Chinese ones, but again, there's nothing to say that some text is bold and some text is not. There's also no explicit font, text size, etc.

In the case of printing HTML, you're still outputting a string. But the computer program reading that string (a web browser) is programmed to interpret text like this is <b>bold</b> as "this is bold" when it converts your string of letters into pixels on the screen. If all text were WYSIWYG, the need for HTML itself would be mitigated -- you would just select text in your editor and bold it instead of typing out the HTML.

Other programs use different systems -- a lot of answers explained a completely different system for printing bold text on terminals. I'm glad you found out how to do what you want to do, but at some point, you'll want to understand how strings and memory work.

share|improve this answer
add comment

Some terminals allow to print colored text. Some colors look like if they are "bold". Try:

print ('\033[1;37mciao!')

The sequence '\033[1;37m' makes some terminals to start printing in "bright white" that may look a bit like bolded white. '\033[0;0m' will turn it off.

share|improve this answer
add comment

Assuming that you really mean "print" on a real printing terminal:

>>> text = 'foo bar\r\noof\trab\r\n'
>>> ''.join(s if i & 1 else (s + '\b' * len(s)) * 2 + s
...         for i, s in enumerate(re.split(r'(\s+)', text)))
'foo\x08\x08\x08foo\x08\x08\x08foo bar\x08\x08\x08bar\x08\x08\x08bar\r\noof\x08\

Just send that to your stdout.

share|improve this answer
add comment

sudo pip install termcolor
and then try this
from termcolor import colored
print colored('Hello', 'green')

and that's it for me

share|improve this answer
add comment

Your Answer


