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

how to print bold font when using f-string?

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

我来到下面这个网站说在字符串前后使用“\033[1m”。问题是如何在 f-string 中使用它以及如何对整数值使用它?谢谢

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

你试过了吗? :

a_string = "abc"
bolded_string = f"3[1m{a_string}3[0m"
print (bolder_string)

与正则字符串相同 试试这个:

name = 'Yacoub'
age = 23
print(f"This is 3[1mbold3[0m and my name is 3[1m{name}3[0m\nI am 3[1m{age}3[0m years old")

输出:

这是粗体,我的名字是Yacoub

23