Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8bc7ef6

Browse files
committed
Close #16665: improve documentation for hex(). Patch by Jessica McKellar.
2 parents d5358b9 + 790bf0d commit 8bc7ef6

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Doc/library/functions.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,19 @@ are always available. They are listed here in alphabetical order.
617617

618618
.. function:: hex(x)
619619

620-
Convert an integer number to a hexadecimal string. The result is a valid Python
621-
expression. If *x* is not a Python :class:`int` object, it has to define an
622-
:meth:`__index__` method that returns an integer.
620+
Convert an integer number to a lowercase hexadecimal string
621+
prefixed with "0x", for example:
622+
623+
>>> hex(255)
624+
'0xff'
625+
>>> hex(-42)
626+
'-0x2a'
627+
628+
If x is not a Python :class:`int` object, it has to define an __index__()
629+
method that returns an integer.
630+
631+
See also :func:`int` for converting a hexadecimal string to an
632+
integer using a base of 16.
623633

624634
.. note::
625635

0 commit comments

Comments
 (0)