From: Antoine Pitrou Date: Sun, 16 Mar 2014 01:12:20 +0000 (+0100) Subject: Close #16665: improve documentation for hex(). Patch by Jessica McKellar. X-Git-Tag: v2.7.7rc1~124 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7692805f77844b664f746e5fe6125c726c22c13;p=python Close #16665: improve documentation for hex(). Patch by Jessica McKellar. --- diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index dec76d3bf4..76564142e6 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -596,8 +596,21 @@ available. They are listed here in alphabetical order. .. function:: hex(x) - Convert an integer number (of any size) to a hexadecimal string. The result is a - valid Python expression. + Convert an integer number (of any size) to a lowercase hexadecimal string + prefixed with "0x", for example: + + >>> hex(255) + '0xff' + >>> hex(-42) + '-0x2a' + >>> hex(1L) + '0x1L' + + If x is not a Python :class:`int` or :class:`long` object, it has to + define an __index__() method that returns an integer. + + See also :func:`int` for converting a hexadecimal string to an + integer using a base of 16. .. note::