The new Python 3.6 f-strings seem like a huge jump in string usability to me, and I would love to jump in and adopt them whole heartedly on new projects which might be runni
here's what I use:
text = "Foo is {age} {units} old".format(**locals())
it unpacks (**
) the dict returned by locals()
which has all your local variables as a dict {variable_name: value}
Note this will not work for variables declared in an outer scope, unless you import it to the local scope with nonlocal
(Python 3.0+).
you can also use
text.format(**locals(),**globals())
to include global variables in your string.