4 ms·
I think you're confusing string interpolation with C-style format strings. Format strings are what you describe: either too weak or a completely insane sub-lan
by lolinder 3y ago
I think you're confusing string interpolation with C-style format strings.
Format strings are what you describe: either too weak or a completely insane sub-language.
The kind of string interpolation that OP is talking about is different in that what is in between the braces is just an expression and can usually be an arbitrary expression. It doesn't need to be a complex mini language because it just uses the same expression language that you're using everywhere else, with the only additional rule being that your expression must return a string (or in some languages something that can be coerced to a string).
From reading this PEP, it sounds like Python's original implementation was a bizarre half measure—it was almost like proper string interpolation but had a bunch of restrictions that showed that they stopped short of changing the parser to just go into expression mode in between the braces.