I am attempting to use the #X format specifier to print a hexadecimal value using capital letters for the "digits" while automatically prepending the usual 0x prefix. For example, decimal 10 should be represented as 0xA.
However, that specifier does not seem to behave in that way:
>>> print(f'{10:#X}')
0XA
>>> '{:#X}'.format(10)
'0XA'
Which looks like the X modifier makes the whole string representation of the number (including the 0x prefix) go through str.upper instead of the "number part" only. I thought that was fair enough but, after checking the Format Specification Mini-Language, it looks like it might not be the intended result (or, at least, it is not clearly documented). Here are the relevant bits:
The
'#'option causes the "alternate form" to be used for the conversion. [...] For integers, when [...] hexadecimal output is used, this option adds the prefix [...]'0x'to the output value.[...]
The available integer presentation types are:
Type Meaning [...] [...] 'x'Hex format. Outputs the number in base 16, using lower-case letters for the digits above 9. 'X'Hex format. Outputs the number in base 16, using upper-case letters for the digits above 9. [...] [...]
And this seems to imply that upper-case letters should only be for non-decimal hexadecimal digits (a, b, c, d, e, f) and therefore should not concern x (from 0x); is that right?