::
- >>> year = 2016 ; event = 'Referendum'
+ >>> year = 2016
+ >>> event = 'Referendum'
>>> f'Results of the {year} {event}'
'Results of the 2016 Referendum'
::
- >>> yes_votes = 42_572_654 ; no_votes = 43_132_495
- >>> percentage = yes_votes/(yes_votes+no_votes)
+ >>> yes_votes = 42_572_654
+ >>> no_votes = 43_132_495
+ >>> percentage = yes_votes / (yes_votes + no_votes)
>>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage)
' 42572654 YES votes 49.67%'
>>> import math
>>> print(f'The value of pi is approximately {math.pi:.3f}.')
+ The value of pi is approximately 3.142.
Passing an integer after the ``':'`` will cause that field to be a minimum
number of characters wide. This is useful for making columns line up. ::
>>> animals = 'eels'
>>> print(f'My hovercraft is full of {animals}.')
My hovercraft is full of eels.
- >>> print(f'My hovercraft is full of {animals !r}.')
+ >>> print(f'My hovercraft is full of {animals!r}.')
My hovercraft is full of 'eels'.
For a reference on these format specifications, see