diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-03-16 01:13:07 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-03-16 01:13:07 (GMT) |
commit | 8bc7ef63a4e838d255c482a6e547438e38ad5526 (patch) | |
tree | 90fcaad7b3bf70d24138f8c3dce77fba45bb50b9 /Doc/library | |
parent | d5358b94d1d462456732cb02a6a1bf32feb1ddc5 (diff) | |
parent | 790bf0db77da018376b50c70b68a48a4a81cf444 (diff) | |
download | cpython-8bc7ef63a4e838d255c482a6e547438e38ad5526.zip cpython-8bc7ef63a4e838d255c482a6e547438e38ad5526.tar.gz cpython-8bc7ef63a4e838d255c482a6e547438e38ad5526.tar.bz2 |
Close #16665: improve documentation for hex(). Patch by Jessica McKellar.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/functions.rst | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 0ee52fa..2b37069 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -617,9 +617,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:: |