Author rurpy2
Recipients docs@python, rurpy2
Date 2012-12-11.20:33:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The documentation of the hex() builtin function is poor.  Specifically it does not say (directly) that:

1. The resulting string is prefixed with "0x".

2. Any a-f characters used are lower case.

3. Negative integers are converted by prefixing a minus sign to hex() of the absolute value of the argument.

4. It should have a cross reference to the %x format of the "%" operator with a note that it is more veratile than the hex() builtin. 

5. It should have a cross reference to the way of performing the inverse operation: hex->int

I am not a good writer but here is an attempt at improving it:

Convert an integer number to a hexadecimal string.  The resulting string is prefixed with "0x" and any alpha characters a-f are lowercase ascii.  Negative integers are converted to hex(abs(x)) prefixed with "-".  In all cases the result is a valid Python expression.

If x is not a Python int object, it has to define an __index__() method that returns an integer.

Note: For another more flexible way of converting an integer to hexadecimal see the "x" and "X" conversion types in link:[4.7.2 -  printf-style String Formatting] and link:[ - Format Specification Mini-Language]

Note: To convert a hexadecimal string to an integer, use link:[int()] with a radix argument of 16. 

Note: To obtain a hexadecimal string representation for a float, use the link:[float.hex()] method.
Date User Action Args
2012-12-11 20:33:17rurpy2setrecipients: + rurpy2, docs@python
2012-12-11 20:33:17rurpy2setmessageid: <>
2012-12-11 20:33:17rurpy2linkissue16665 messages
2012-12-11 20:33:16rurpy2create