使用f-string时如何打印粗体字体?

rou*_*dan 5 python ansi-escape

对于f字符串,如何打印整数或字符串的粗体字体?

我来到下面的网站,说在字符串之前和之后使用“\033[1m”。问题是如何在 f 字符串中使用它以及如何对整数值执行此操作?谢谢

https://www.kite.com/python/answers/how-to-print-in-bold-in-python

Abu*_*bad 9

它与常规字符串相同尝试以下操作:

name = 'Yacoub'
age = 23
print(f"This is \033[1mbold\033[0m and my name is \033[1m{name}\033[0m\nI am \033[1m{age}\033[0m years old")
Run Code Online (Sandbox Code Playgroud)

输出:

这是大胆的,我的名字是雅各布

23