monica_b1998@lemmy.world to Python@programming.dev · 2 months agoPython String Formatting: f-strings vs .format() vs %slicker.meexternal-linkmessage-square15fedilinkarrow-up142
arrow-up142external-linkPython String Formatting: f-strings vs .format() vs %slicker.memonica_b1998@lemmy.world to Python@programming.dev · 2 months agomessage-square15fedilink
minus-squareCaveman@lemmy.worldlinkfedilinkarrow-up9·2 months agoI worked in python when f-strings were pretty new. Didn’t realise why you would use anything else. It just reads better.
minus-squareMichal@programming.devlinkfedilinkarrow-up4·2 months agoMost importantly you can’t use them with translated strings, so it’s not usable for user facing strings unless you don’t care. This limits fstring usefulness a lot in the projects I work on.
minus-squareBadabinski@kbin.earthlinkfedilinkarrow-up9·2 months agoLuckily, there’s now t-strings (e.g. t"{buh}") for that use case (among many others). Here’s the PEP: https://peps.python.org/pep-0750/
I worked in python when f-strings were pretty new. Didn’t realise why you would use anything else. It just reads better.
Most importantly you can’t use them with translated strings, so it’s not usable for user facing strings unless you don’t care. This limits fstring usefulness a lot in the projects I work on.
Luckily, there’s now t-strings (e.g.
t"{buh}") for that use case (among many others). Here’s the PEP: https://peps.python.org/pep-0750/