Python - Change print console font family/style

我怕爱的太早我们不能终老 提交于 2021-02-05 08:11:51

问题


The question's 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, Jupyter Notebooks 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"


回答1:


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.



来源:https://stackoverflow.com/questions/51228122/python-change-print-console-font-family-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!