3 ms·
The difference is, > "Foo " + bar + " baz" is not a string literal, neither is one using format or % function. All of those things return dead strings. This
by imakesnowflakes 11y ago
The difference is,
> "Foo " + bar + " baz"
is not a string literal, neither is one using format or % function. All of those things return dead strings. This pep is about creating a kind of 'live' string literal, which python does not have right now (or need IMHO). So this is not merely a nicer syntax.
- svieira 11y agoIt is not live (unless I am mis-understanding what you mean by live) - it is evaluated once. That is to say: def magic(a, b): return f"{a} and {b}" s = magic(4, 8) print(s) a, b = 3, 7 print(s) prints `4 and 8` in both cases.
- imakesnowflakes 11y agoIt is live in the sense that you can take that string literal and put it in a different context and it will result in a different evaluation, possibly yielding different value for the string and possibly different side effects (after calls to evaluate expressions).