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

Skip to content

Commit 790bf0d

Browse files
committed
Close #16665: improve documentation for hex(). Patch by Jessica McKellar.
1 parent 0392271 commit 790bf0d

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
@@ -608,9 +608,19 @@ are always available. They are listed here in alphabetical order.
608608

609609
.. function:: hex(x)
610610

611-
Convert an integer number to a hexadecimal string. The result is a valid Python
612-
expression. If *x* is not a Python :class:`int` object, it has to define an
613-
:meth:`__index__` method that returns an integer.
611+
Convert an integer number to a lowercase hexadecimal string
612+
prefixed with "0x", for example:
613+
614+
>>> hex(255)
615+
'0xff'
616+
>>> hex(-42)
617+
'-0x2a'
618+
619+
If x is not a Python :class:`int` object, it has to define an __index__()
620+
method that returns an integer.
621+
622+
See also :func:`int` for converting a hexadecimal string to an
623+
integer using a base of 16.
614624

615625
.. note::
616626

0 commit comments

Comments
 (0)