How can I make text bold in Python? [duplicate]


This question already has an answer here:

<ul><li> <a href="/questions/8924173/how-do-i-print-bold-text-in-python" dir="ltr" rel="nofollow">How do I print bold text in Python?</a> <span class="question-originals-answer-count"> 10 answers </span> </li> </ul>

I want to be able to change the text to bold in Python. Is there a way to do that?

I have been able to change colors with termcolor but nothing so far with bold text. Has anyone tried doing it before?


You might want to try ANSI escape sequences <strong>if</strong> your platform allows it.

Crossposting from related - and possible duplicate - SO questions: <a href="https://stackoverflow.com/questions/8924173/python-print-bold-text" rel="nofollow">1</a> <a href="https://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python" rel="nofollow">2</a>

Before you proceed, please read the warnings in the above links to make sure your operating system and Python version will allow you to properly render this.

You can define a class containing all of the ANSI escape sequences you need.

class style: BOLD = '\033[1m' END = '\033[0m'

Then print them via concatenated class calls:

print style.BOLD + 'This is my text string.' + style.END

If you don't want to go through the hassle of creating an entire class just to get bold text, you can obviously concatenate them directly instead. However, if your code is open-source and not for personal use, make sure you tell other potential readers what this does!

print '\033[1m' + 'This is my text string.' + '\033[0m'

Does this answer your question?

Edit: JYelton beat me to it. I'm such a slow typer...


  • Java Date object constructor for getting string is deprecated
  • IllegalArgumentException caught when parsing URL with JSON String
  • https in htaccess and order of rules (using Expression Engine)
  • Submission of new app with iAds
  • ASP.NET, C# How to Pass a StringQuery to a custom SQL Command
  • Merge list of objects into consistent list based on common matching attribute in Python
  • On which thread JavaFX change listeners are executed ?
  • Consuming a web service with the Netbeans Platform
  • Insert records if not exist SQL Server 2005
  • Does the Azure table storage API cache results?
  • How do you create a Fuseki SPARQL server using the Apache Jena Java API?
  • Unique Permutations - with exceptions
  • How to use Windows Media Foundation with UWP without a topology
  • Cloud Code function running twice
  • joining two bezier curves
  • Overlapping controls in Windows XP
  • Sequential (transactional) API calls in angular 4 with state management
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • x64 applications using gdi+: what are the consequences on performance?
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • How to install a .deb file on a jailbroken iphone programmatically?
  • How to delay loading a property with linq to sql external mapping?
  • Recording logins for password protected directories
  • SignalR .NET Client Invoke throws an exception
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Lost migrations and Azure database is now out of sync
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • jQuery show() function is not executed in Safari if submit handler returns true
  • How do I fake an specific browser client when using Java's Net library?
  • Sony Xperia Z Tablet not found by adb
  • How to get a value (ex: baseURL) in every Karate feature?
  • Javascript Callbacks with Object constructor
  • Validaiting emails with Net.Mail MailAddress
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Matrix multiplication with MKL
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper folder structure for lots of source files
  • how does django model after text[] in postgresql [duplicate]
  • Cant find why the layout is getting smaller
  • How does Linux kernel interrupt the application?