From Python 2.6:
>>> "www.someurl.com/{0}/blah.html".format(100)
'www.someurl.com/100/blah.html'
To support older environments, the operator %has a similar role:
>>> "www.someurl.com/%d/blah.html" % 100
'www.someurl.com/100/blah.html'
If you want to support named arguments, you can pass dict.
>>> url_args = {'num' : 100 }
>>> "www.someurl.com/%(num)d/blah.html" % url_args
'www.someurl.com/100/blah.html'
, , :
>>> '%d: %s' % (1, 'string formatting',)
'1: string formatting'
__str__. [*] Python docs. Python 3+, .
, join . .
>>> ' '.join(['2:', 'list', 'of', 'strings'])
'2: list of strings'
- , (, Python < 2.5), . . , .
[*] Unicode __unicode__.
>>> u'3: %s' % ':)'
u'3: :)'