4 ms·
String interpolation is not the same as C-style format strings. Format strings live in userland as part of the standard library and have the many drawbacks you
by lolinder 3y ago
String interpolation is not the same as C-style format strings.
Format strings live in userland as part of the standard library and have the many drawbacks you note.
Proper string interpolation is part of the language grammar itself, and the bits between the braces are usually full-fledged expressions that resolve variable names the same way that every other expression does. Since it's a language construct, it's trivial for it to just compile down to a series of concat(a, b) operations.
It sounds like Python had a half-complete string interpolation mechanism until this PEP, so I can understand why there'd be confusion on this point, but that is a problem with Python's implementation, not something that is an inherent risk with string interpolation. In a new language it is easier to implement string interpolation properly than to introduce a half measure like Python's.