Instead of reading like 10 PEPs for f strings, I just use the + operator on strings and backslash escaping, big whoop.
Instead of reading like 10 PEPs for f strings, I just use the + operator on strings and backslash escaping, big whoop.
- 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.
print(f"Age: {age}")
Thus concludes the lecture on f-strings.
f'{a} = {functionThatReturnsAButHasSideEffects()}'
f-string is shorter, less err prone, and faster for medium complexity or above.
>>> age = 32
>>> print("Age: " + age)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str
>>> print("Age: " + str(age))
Age: 32
As a side note, I always found it amusing that Python is dynamic but doesn't let you do this, while C# has static typing but lets you do string + number. (I looked into it a while back, I think it's because both are Object, so it does operator overloading on Object+Object and then checks the types...)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.
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
> senior python developers > great for gatekeeping and job security
Ah, okay, it's just a troll.
"%T", T t
not "{ (expr).__str__()} "
> Ah, okay, it's just a troll.If that helps you sleep at night