Search code examples
pythonansi-escape

how to print bold font when using f-string?


for f-string, how to print bold font for either integer or string?

I came to this below website saying using "\033[1m" before and after string. Question is how to use it inside f-string and how to do it for integer values as well? Thanks

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


Solution

  • It is the same as the regular string Try this:

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

    Output:

    This is bold and my name is Yacoub

    I am 23 years old