python, format string

后端 未结 8 1682
野性不改
野性不改 2020-12-28 18:00

I am trying to build a format string with lazy argument, eg I need smth like:

\"%s \\%s %s\" % (\'foo\', \'bar\') # \"foo %s bar\"

how can

相关标签:
8条回答
  • 2020-12-28 18:45
    "%s %%s %s" % ('foo', 'bar') # easy!
    

    Double % chars let you put %'s in format strings.

    0 讨论(0)
  • 2020-12-28 18:52
    >>> "%s %%s %s" % ('foo', 'bar')
    'foo %s bar'
    
    0 讨论(0)
提交回复
热议问题