on str.format and f-strings

Meredith Montgomery mmontgomery at levado.to
Mon Sep 5 15:07:57 EDT 2022


It seems to me that str.format is not completely made obsolete by the
f-strings that appeared in Python 3.6.  But I'm not thinking that this
was the objective of the introduction of f-strings: the PEP at 

  https://peps.python.org/pep-0498/#id11

says so explicitly.  My question is whether f-strings can do the
following nice thing with dictionaries that str.format can do:

--8<---------------cut here---------------start------------->8---
def f():
  d = { "name": "Meredith", "email": "mmontgomery at levado.to" }
  return "The name is {name} and the email is {email}".format(**d)
--8<---------------cut here---------------end--------------->8---

Is there a way to do this with f-strings?


More information about the Python-list mailing list