Simple positional formatting is probably the most common use-case. Use it
if the order of your arguments is not likely to change and you only have
very few elements you want to concatenate.
Since the elements are not represented by something as descriptive as a name this simple style should only be used to format a relatively small number of elements.
Since the elements are not represented by something as descriptive as a name this simple style should only be used to format a relatively small number of elements.
Old
'%s %s' % ('one', 'two')
New
'{} {}'.format('one', 'two')
Output
one two
Old
'%d %d' % (1, 2)
New
'{} {}'.format(1, 2)
Output
1 2
No comments:
Post a Comment