3 ms·
However, str.format() is not without its issues. Chief among them is its verbosity. For example, the text 'value' is repeated here: >>> value = 4 * 20
by RodericDay 11y ago
However, str.format() is not without its issues. Chief among them is its verbosity. For example, the text 'value' is repeated here:
>>> value = 4 * 20
>>> 'The value is {value}.'.format(value=value)
'The value is 80.'
Even in its simplest form, there is a bit of boilerplate, and the value that's inserted into the placeholder is sometimes far removed from where the placeholder is situated:
>>> 'The value is {}.'.format(value)
'The value is 80.'
With an f-string, this becomes:
>>> f'The value is {value}.'
'The value is 80.'
Yeah I've had this thought before.
- Retra 11y ago>>> 'The value is '+value+'.' 'The value is 80.' Boilerplate? It's one extra character.