]> granicus.if.org Git - python/commitdiff
Close #16665: improve documentation for hex(). Patch by Jessica McKellar.
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 16 Mar 2014 01:12:20 +0000 (02:12 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 16 Mar 2014 01:12:20 +0000 (02:12 +0100)
Doc/library/functions.rst

index dec76d3bf486a331bb91a32d31f496be4383cc68..76564142e6b4c41c48e4728fd20db406b4756dec 100644 (file)
@@ -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::