0

If there is a variable var=0.00012646547, and it is being printed using the "=" syntax feature provided by f-string as

print(f'{var=}')

, is there a way to format the output which would provide a similar result as the following code ?

print('var\t=\t{0:.3e}'.format(var))

Naturally print(f'{var\t=%.3e}') doesnot work as it is messing with the f-string syntax

  • You can actually use the formatting syntax, kind of. `print(f'var\t=\t{var:.10f}')` will print a tabulator and your `var` with 10 decimal places. – white Feb 15 '23 at 16:45
  • `print(f'var\t=\t{var:.10f}')` defeats the purpose of using the '=' syntax, in where we only have to write the variable once. – iampratham Feb 15 '23 at 20:05

0 Answers0