How do I use Python to easily expand variables to strings?

前端 未结 4 1245
一个人的身影
一个人的身影 2021-02-05 07:52

What\'s a nice idiom to do this:

Instead of: print \"%s is a %s %s that %s\" % (name, adjective, noun, verb)

I want to be able to do something to th

4条回答
  •  天命终不由人
    2021-02-05 08:04

    Since Python 3.6 you can now use this syntax, called f-strings, which is very similar to your suggestion 9 years ago

提交回复
热议问题