diff -r 9b67e9c1c764 Doc/library/functions.rst --- a/Doc/library/functions.rst Tue Jul 09 18:37:12 2013 -0500 +++ b/Doc/library/functions.rst Tue Jul 09 18:55:39 2013 -0500 @@ -607,9 +607,29 @@ .. function:: hex(x) - Convert an integer number to a hexadecimal string. The result is a valid Python - expression. If *x* is not a Python :class:`int` object, it has to define an - :meth:`__index__` method that returns an integer. + Convert an integer number to a hexadecimal string. The resulting + string is prefixed with "0x" and uses ASCII characters 0-9 and + lowercase a-f. Negative integers are converted to hex(abs(x)) prefixed + with "-". In all cases the result is a valid Python `hexinteger` literal + (see link:[Python Lang Ref, sec 2.4.4. Integer literals]). + + If x is not a Python `int` object, it has to define an __index__() + method that returns an integer. + +Some examples:: + + >>> hex(3) + '0x3' + >>> hex(10) + '0xa' + >>> hex(-4) + '-0x4' + >>> hex(16) + '0x10' + >>> hex('word') + Traceback (most recent call last): + File "", line 1, in + TypeError: hex() argument can't be converted to hex .. note::