What can’t be done with f-string that you can do when using . format?

Asked

Viewed 584 times

1

Hello I would like to know in which cases I need to use the format method instead of f-string because with f-string it is not possible to do. For example I think it is not possible with f-string to write a formatted number:

'fps: {:.1f}'.format(55.3578) => fps: 55.3
  • fstring allows you to format decimal places as well as format. in your case would suffice f'fps: {55.3578:.1f}', assuming it’s in python 3.6+. As far as I know, I don’t think there’s anything you can do with format that you can’t do with fstring

1 answer

2

In fact, it does.

f"fps {55.3578:.1f}"

The fstrings accept any valid Python expression, format.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.