mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Close #16665: improve documentation for hex(). Patch by Jessica McKellar.
This commit is contained in:
parent
0392271073
commit
790bf0db77
1 changed files with 13 additions and 3 deletions
|
@ -608,9 +608,19 @@ are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
.. function:: hex(x)
|
.. function:: hex(x)
|
||||||
|
|
||||||
Convert an integer number to a hexadecimal string. The result is a valid Python
|
Convert an integer number to a lowercase hexadecimal string
|
||||||
expression. If *x* is not a Python :class:`int` object, it has to define an
|
prefixed with "0x", for example:
|
||||||
:meth:`__index__` method that returns an integer.
|
|
||||||
|
>>> 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::
|
.. note::
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue