4 ms·
The thing about the latter form is that you can do something like '{0} {1} {0} {2}'.format('apple', 'banana', 'orange') which results in 'apple banana apple ora
by gluelogic 11y ago
The thing about the latter form is that you can do something like '{0} {1} {0} {2}'.format('apple', 'banana', 'orange') which results in 'apple banana apple orange'
- squeaky-clean 11y agoYou can also use keyword arguments, which is really helpful in certain situation. Example from the docs: 'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')
- wyldfire 11y agoYou could do that before with % substitution too. But I prefer .format() because (1) it's the new idiom and (2) will coerce to string without me binding the type in the format string.