Using multiple arguments for string formatting in Python (e.g., '%s … %s')

后端 未结 8 2107
谎友^
谎友^ 2020-12-04 08:16

I have a string that looks like \'%s in %s\' and I want to know how to seperate the arguments so that they are two different %s. My mind coming from Java came u

8条回答
  •  粉色の甜心
    2020-12-04 08:53

    For completeness, in python 3.6 f-string are introduced in PEP-498. These strings make it possible to

    embed expressions inside string literals, using a minimal syntax.

    That would mean that for your example you could also use:

    f'{self.author} in {self.publication}'
    

提交回复
热议问题