110 ms·
!r is one of a class of conversion flags, others are !a which uses ascii(), !s which uses str(). “=” in the format-spec (the thing that comes after the “:”) is
by dragonwriter 6y ago
!r is one of a class of conversion flags, others are !a which uses ascii(), !s which uses str().
“=” in the format-spec (the thing that comes after the “:”) is the numeric padding alignment specifier (other alignment specifiers are left “<”, right “>”, and center “^”.)
- CGamesPlay 6y agoOh, neat, so I can stack them: foo = 'foo' print(f"{foo=!r:>20}") print(f"{foo.upper()=!r:>20}") The `=` you pointed out is a special case, however, and not part of the alignment specification. Sadly, this means that the above snippet is not as nicely formatted as I'd like. Still, it does seem useful for these cases: print(f"{x=:.2f} {dx=:.2f} {dot_product=:.4f}")