Comment by roenxi
3 days ago
This looks like a cheatsheet for writing a hard-to-read Python script. I don't know who gets karmic brownie points for a f"{string:>20}" field, but under most normal cases it'd be better to use rjust() directly and not force people to remember Yet Another DSL.
Once a reader could be reasonably expected to consult reference material while working out what a print() is doing something has gone wrong. This is the programmer equivalent of wearing too much makeup.
You haven't seen the full depth yet. Suppose that you encountered with this line:
What will it print? Here is the official explanation from https://docs.python.org/3.12/library/string.html#formatspec:
Make sense? You now should be able to see why it's called f-string.
Yes, it's a generalisation of `%g` in f-string's ancestor printf(3). This is what people expect to find in formatting templates.
I don't know why people look at paragraphs of documentation that explain the exact results in strange edge cases (which have to exist because of the underlying complexity; in this example, Python can't change how IEEE-754 works, nor the original C printf specifier they're emulating) and conclude that this proves some strange and unexpected complexity was introduced.
When documentation isn't this thorough, people complain about that, too.
Maybe should be called “iq-string” for Interview Question string.