by CmdrKrool · 11mo ago · 0 comments
String operations in Python are fast as well. f-strings are the fastest formatting style, while even the slowest style is still measured in just nano-seconds.
Concatenation (+) 39.1 ns (25.6M ops/sec)
f-string 64.9 ns (15.4M ops/sec)
It says f-strings are fastest but the numbers show concatenation taking less time? I thought it might be a typo but the bars on the graph reflect this too? "literal1 " + str(expression) + " literal2"
vs f"literal1 {expression} literal2"
The only case that would be faster is something like: "foo" + str(expression)