[Python-checkins] cpython (2.7): Close #16665: improve documentation for hex(). Patch by Jessica McKellar.

antoine.pitrou python-checkins at python.org
Sun Mar 16 02:16:57 CET 2014


http://hg.python.org/cpython/rev/d14beaf03f55
changeset:   89681:d14beaf03f55
branch:      2.7
parent:      89676:772404a89b88
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sun Mar 16 02:12:20 2014 +0100
summary:
  Close #16665: improve documentation for hex().  Patch by Jessica McKellar.

files:
  Doc/library/functions.rst |  17 +++++++++++++++--
  1 files changed, 15 insertions(+), 2 deletions(-)


diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -596,8 +596,21 @@
 
 .. 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::
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list