Inconsistency in hex()
danb_83 at yahoo.com
Tue Jul 12 19:51:30 CEST 2005
Steven D'Aprano wrote:
> hex() of an int appears to return lowercase hex digits, and hex() of a
> long uppercase.
> >>> hex(75)
> >>> hex(75*256**4)
> By accident or design? Apart from the aesthetic value that lowercase hex
> digits are ugly, should we care?
> It would also be nice if that trailing L would disappear.
Yes, but that can easily be worked around.
>>> def hex(x):
... """Return the hexadecimal representation of an integer."""
... return __builtins__.hex(x).upper().rstrip('L')
>>> hex(75 * 256**4)
More information about the Python-list