| ▲ | TZubiri 3 hours 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. |
|
| ▲ | PyWoody 3 hours ago | parent | next [-] |
| Instead of 10 PEPs, you could read one helpful cheatsheet: https://www.pythonmorsels.com/string-formatting/#cheat-sheet.... |
| |
| ▲ | TZubiri 3 minutes ago | parent [-] | | Doesn'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. |
|
|
| ▲ | andai 3 hours ago | parent | prev | next [-] |
| age = 32 print(f"Age: {age}") Thus concludes the lecture on f-strings. |
| |
| ▲ | kzrdude 2 hours ago | parent | next [-] | | I find it funny and satisfying that Python has converged to it's own "printf", by which I mean print(f""). | |
| ▲ | layer8 an hour ago | parent | prev [-] | | It’s unclear what the big advantage is over `print("Age: "+age)`. It’s even more characters, in that specific example. | | |
| ▲ | mixmastamyk an hour ago | parent | next [-] | | Toy examples aren’t the use case, rather multiple variables or expressions, perhaps with formatting (padding) as well. f-string is shorter, less err prone, and faster for medium complexity or above. | |
| ▲ | an hour ago | parent | prev | next [-] | | [deleted] | |
| ▲ | kstrauser an hour ago | parent | prev [-] | | If age is a number, that won’t work. | | |
| ▲ | layer8 an hour ago | parent [-] | | Admittedly I’m not so familiar with Python; it does work in Java. In that case, introducing a less hazardous string concatenation operator would seem more universally useful. | | |
| ▲ | kstrauser an hour ago | parent [-] | | In Python, that less hazardous string concatenation operator is an f-string. | | |
| ▲ | layer8 24 minutes ago | parent [-] | | I’m assuming you can only use it with string literals, hence it is less universally useful. |
|
|
|
|
|
|
| ▲ | jheriko 2 hours ago | parent | prev | next [-] |
| [dead] |
|
| ▲ | smohare 3 hours ago | parent | prev [-] |
| Right, 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 an hour ago | parent [-] | | Personally I do find the first version clearer, because it is based on general language rules. |
|