-3

How can I convert this to an f-string?

message = '{status} : {method} : {url}'.format(**call_components)
  • If you have variables with those names, then all you have to do is add the `f` to the beginning. e.g `f'...'` – 2pichar Apr 06 '22 at 17:54
  • ...and if you don't, then you can either use `call_components["status"]`, `call_components["method"]`, etc., or just use this `format` command because it works nicely. Not everything has to be f-strings. – nneonneo Apr 06 '22 at 17:56

1 Answers1

1

str.format() is usually fine, but if you really want an f-string then it would look like this: message = f'{call_components["status"]} : {call_components["method"]} : {call_components["url"]}'

Ukulele
  • 612
  • 2
  • 10
  • Which, arguably, is much harder to read than the `.format` solution. (Your solution is perfectly fine - but it would be better to stick to `.format` in such a case.) – nneonneo Apr 06 '22 at 18:00
  • Yes, I agree, I would use str.format() too, but this is the answer to the question... – Ukulele Apr 06 '22 at 18:07