4 ms·
Been using python for almost 10 years. I never use any of the funky strings. Instead of reading like 10 PEPs for f strings, I just use the + operator on string
by TZubiri 3mo ago
Been using python for almost 10 years. I never use any of the funky strings.
Instead of reading like 10 PEPs for f strings, I just use the + operator on strings and backslash escaping, big whoop.
- smohare 3mo agoRight, because x + " " + y is more clear than of simply f"{x} {y}". Been using python for longer than 10 years and immediately started using f-strings when I could. It takes almost no time to understand the basics.
- layer8 3mo agoPersonally I do find the first version clearer, because it is based on general language rules.
- TZubiri 3mo agoEspecially if you come from other languages. a + " " + b will be clearer to devs that aren't senior python developers. the f string thing is just a marginal improvement at the cost of alienating other devs. But it's great for gatekeeping and job security.
- shooly 3mo ago> come from other languages According to Wikipedia[1] the history of string formatting goes back to 1950s. Also, basically every major programming language these days implements it in some form. [1] https://en.wikipedia.org/wiki/Printf https://en.wikipedia.org/wiki/Printf > senior python developers > great for gatekeeping and job security Ah, okay, it's just a troll.
- TZubiri 3mo agoBut the link you shared describes a syntax that is very different. "%T", T t not "{ (expr).__str__()} " > Ah, okay, it's just a troll. If that helps you sleep at night
- andai 3mo agoage = 32 print(f"Age: {age}") Thus concludes the lecture on f-strings.
- kzrdude 3mo agoI find it funny and satisfying that Python has converged to it's own "printf", by which I mean print(f"").
- layer8 3mo agoIt’s unclear what the big advantage is over `print("Age: "+age)`. It’s even more characters, in that specific example.
- kstrauser 3mo agoIf age is a number, that won’t work.
- PyWoody 3mo agoInstead of 10 PEPs, you could read one helpful cheatsheet: https://www.pythonmorsels.com/string-formatting/#cheat-sheets https://www.pythonmorsels.com/string-formatting/#cheat-sheet....
- TZubiri 3mo agoDoesn't cover: - the trailing slash detail detailed in the OP - raw strings at all - more complex stuff like raw format strings Also, my mind is a temple, I don't learn python from cheatsheets from random secondary sources.
- jheriko 3mo ago[dead]