4 ms·
TIL. str.format and % parse the format string at runtime, so it's expected that they're slower. But I thought the f-string desugars to something similar to the
by owl57 3y ago
TIL. str.format and % parse the format string at runtime, so it's expected that they're slower. But I thought the f-string desugars to something similar to the last one. Turns out it's not, it compiles to specialized opcodes and avoids function calls:
https://bugs.python.org/issue25483 https://bugs.python.org/issue25483
https://bugs.python.org/issue27078 https://bugs.python.org/issue27078