From c7692805f77844b664f746e5fe6125c726c22c13 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 16 Mar 2014 02:12:20 +0100 Subject: [PATCH] Close #16665: improve documentation for hex(). Patch by Jessica McKellar. --- Doc/library/functions.rst | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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:: -- 2.50.1