4 ms·
Also not a fan. The two existing methods of string formatting are sufficient: "%s %s %s" % (a, b, a) "{} {} {}".format(a, b, a) If you want placeholde
by Rangi42 11y ago
Also not a fan. The two existing methods of string formatting are sufficient:
"%s %s %s" % (a, b, a)
"{} {} {}".format(a, b, a)
If you want placeholders to match variable names, you can do:
"{a} {b} {a}".format(a=a, b=b)
"{a} {b} {a}".format(**locals())
So this is just unnecessary (especially since the "f" prefix is easier to miss than a "format" method):
f"{a} {b} {a}"
And this is downright obfuscated—putting operators inside of string literals:
f"{a + ' ' + b + ' ' + a}"
- deleted 11y ago[deleted]
- roywiggins 11y agoThe PEP says that locals() and globals() solutions were considered, and discarded: https://www.python.org/dev/peps/pep-0498/#no-use-of-globals-or-locals https://www.python.org/dev/peps/pep-0498/#no-use-of-globals-... You could argue that's not a good enough reason, but it's there.
- eugenekolo2 11y agoI certainly agree about your last statement, I have no clue what that would do without reading the spec. I'd guess an error, but apparently not.