
18 Sep
2020
18 Sep
'20
2:36 a.m.
On Fri, Sep 18, 2020 at 09:05:39AM +1000, Chris Angelico wrote:
f-strings are not literals. They are a form of eval().
Oh, that makes 'em sound way too scary :) They're more akin to a list display - a syntactic structure that yields a well-defined object, and has expressions inside it.
*shrug*
Okay, but either way they certainly aren't a literal. Anyone who doubts that ought to disassemble an f-string and see for themselves:
import dis code = compile("f'{x+1} {x-1}'", '', 'eval') dis.dis(code)
--
Steve