Hello all, I was wondering if there is any particular reason to prefer older style .format()
or even %
formatting over f-strings? I see some devs who are quick to embrace new things (e.g., Adam Johnson) are still using %
formating, and wonder what the reasons are? Is there some sort of security concern with using f-strings vs. .format()
or %
? I know that f-strings are typically the fastest, so some folks sticking to older methods has me wondering if they know something I’m missing!
There are a couple of limitations where forms other than f-strings are preferred, particularly in areas where you’re working with dynamically defined data. In other words, you can use .format()
or %
with formatting strings that themselves are dynamically generated.
I can store sets of formatting strings in the database, and select among them at run time, formatting variables using %
. I can’t do that (to my knowledge) with an f-string.
1 Like
Thank you Ken, that makes sense and aligns precisely with where I saw %
used. Thank you so much for answering my question. You’re an amazing source of knowledge, always willing to share that knowledge, and yet full of patience. We’re all incredibly lucky on this forum.