python, format string

后端 未结 8 1770
野性不改
野性不改 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:25

    with python 2.6:

    >>> '{0} %s {1}'.format('foo', 'bar')
    'foo %s bar'
    

    or with python 2.7:

    >>> '{} %s {}'.format('foo', 'bar')
    'foo %s bar'
    

提交回复
热议问题