3

The question is straightforward, is it possible to change the font family of text in a Python print() output? Like Times New Roman, Arial, or Comic Sans?

I only want to change some of the output. Not all of the text like in this question.

I'm using Python 3 and Jupyter Notebook on a Mac.

I know it's possible to make certain text bold like so:

bold_start = '\033[1m'
bold_end   = '\033[0m'

print(bold_start, "Hello", bold_end, "World")

This outputs "Hello World" instead of "Hello World" or "Hello World"

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Patrick Stetz
  • 455
  • 2
  • 7
  • 14

1 Answers1

4

Python strings are just strings of Unicode characters, they don't say anything about font one way or another. The font is determined by whatever is rendering the characters, e.g. the terminal program you're using, or the browser you're using. The print function just spits out the resulting string.

As you pointed out, if you're in a terminal that understands those escape sequences, then you can use those to affect the output. If your output is a web page, then you can embed html code to specify whatever you like, but all the python interpreter sees is a string of characters, not a string of characters in any particular font.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
OldGeeksGuide
  • 2,888
  • 13
  • 23