effectivepython
effectivepython copied to clipboard
Item #20: print with % format string instead of f-string
This code snippet:
try:
result = careful_divide(x, y)
except ValueError:
print('Invalid inputs')
else:
print('Result is %.1f' % result)
The print
at the end should be print(f'Result is {result:.1f}')
Hi Brett,
I think that should be:
print(f'Result is {result:.1f}')
Yes I got it backwards, thanks!