Why does the numeric alignment option = inserts padding after the prefix 0x in Python's format function:
>>> "{: =+#8x}".format(4)
'+0x 4'
i.e. why is the output '+0x 4' and not '+ 0x4'?
The docs are a bit ambiguous saying:
Forces the padding to be placed after the sign (if any) but before the digits.
Technically 0 in 0x is a digit, but 0x is treated in the same way as a sign in the above example.
I would say that it is mostly useful with zero padding
Currently:
>>> "{:0=+#8x}".format(4)
'+0x00004'
But would you prefer: '+00000x4' ? I don't think so, as this isn't even a valid number
+00000x4
^
SyntaxError: invalid syntax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With