Python-更改打印控制台字体系列/样式 [英] Python - Change print console font family/style

查看:249
本文介绍了Python-更改打印控制台字体系列/样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单,是否可以在Python print()输出中更改文本的字体系列?像Times New Roman,Arial或Comic Sans?

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.

我正在Mac上使用Python 3,Jupyter Notebooks.

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")

这将输出" Hello 世界",而不是" Hello World "

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

推荐答案

Python字符串只是unicode字符的字符串,它们没有以任何方式说明字体.字体取决于呈现字符的方式,例如您正在使用的终端程序或正在使用的浏览器.打印功能只是吐出结果字符串.如您所指出的,如果您在可以理解这些转义序列的终端中,则可以使用它们来影响输出.如果您的输出是网页,则可以嵌入html代码以指定所需的内容,但是python解释器看到的只是一个字符串,而不是任何特定字体的字符串.

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.

这篇关于Python-更改打印控制台字体系列/样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆