-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Milestone
Description
>>> value = 1234
>>> f'input={value:#06x}'
'input=0x04d2'f'{date} was on a {date:%A}'
'1991-10-12 was on a Saturday'Format specifiers may also contain evaluated expressions. This allows code such as:
>>> width = 10
>>> precision = 4
>>> value = decimal.Decimal('12.34567')
>>> f'result: {value:{width}.{precision}}'
'result: 12.35'Implement this in fstring!
Hint:
f'abc{expr1:spec1}{expr2!r:spec2}def{expr3}ghi'Might be evaluated as:
'abc' + format(expr1, spec1) + format(repr(expr2), spec2) + 'def' + format(expr3) + 'ghi'