summaryrefslogtreecommitdiffstats
path: root/Doc/library/functions.rst
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-03-16 01:12:20 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-03-16 01:12:20 (GMT)
commit790bf0db77da018376b50c70b68a48a4a81cf444 (patch)
tree2f15de4624f5785844ac1943b3c2b8a1d7fbb1d9 /Doc/library/functions.rst
parent039227107389277e48428b7a7e75ff904ca7e90d (diff)
downloadcpython-790bf0db77da018376b50c70b68a48a4a81cf444.zip
cpython-790bf0db77da018376b50c70b68a48a4a81cf444.tar.gz
cpython-790bf0db77da018376b50c70b68a48a4a81cf444.tar.bz2
Close #16665: improve documentation for hex(). Patch by Jessica McKellar.
Diffstat (limited to 'Doc/library/functions.rst')
-rw-r--r--Doc/library/functions.rst16
1 files changed, 13 insertions, 3 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index ae29cd8..7ed25c1 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -608,9 +608,19 @@ are always available. They are listed here in alphabetical order.
.. 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 lowercase hexadecimal string
+ prefixed with "0x", for example:
+
+ >>> hex(255)
+ '0xff'
+ >>> hex(-42)
+ '-0x2a'
+
+ If x is not a Python :class:`int` 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::