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

后端 未结 8 2100
谎友^
谎友^ 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:50

    You must just put the values into parentheses:

    '%s in %s' % (unicode(self.author),  unicode(self.publication))
    

    Here, for the first %s the unicode(self.author) will be placed. And for the second %s, the unicode(self.publication) will be used.

    Note: You should favor string formatting over the % Notation. More info here

提交回复
热议问题