Skip to content

Commit 6678637

Browse files
committed
pythongh-100428: Make int documentation more accurate
- Remove first link to lexical definition of integer literal, since it doesn't apply (differs in handling of leading zeros, base needs to be explicitly specified, unicode digits are allowed) - Better describe handling of leading zeros and unicode digits - Base 0 does not work exactly as like a code literal, since it allows Unicode digits. Link code literal to lexical definition of integer literal.
1 parent 4cc63e0 commit 6678637

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Doc/library/functions.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -890,17 +890,20 @@ are always available. They are listed here in alphabetical order.
890890
For floating point numbers, this truncates towards zero.
891891

892892
If *x* is not a number or if *base* is given, then *x* must be a string,
893-
:class:`bytes`, or :class:`bytearray` instance representing an :ref:`integer
894-
literal <integers>` in radix *base*. Optionally, the literal can be
895-
preceded by ``+`` or ``-`` (with no space in between) and surrounded by
896-
whitespace. A base-n literal consists of the digits 0 to n-1, with ``a``
893+
:class:`bytes`, or :class:`bytearray` instance representing an integer
894+
literal in radix *base*. Optionally, the literal can be
895+
preceded by ``+`` or ``-`` (with no space in between), have leading zeros,
896+
or be surrounded by whitespace.
897+
898+
A base-n literal consists of Unicode digits representing 0 to n-1, with ``a``
897899
to ``z`` (or ``A`` to ``Z``) having
898-
values 10 to 35. The default *base* is 10. The allowed values are 0 and 2--36.
900+
values 10 to 35. The default *base* is 10. The allowed bases are 0 and 2--36.
899901
Base-2, -8, and -16 literals can be optionally prefixed with ``0b``/``0B``,
900902
``0o``/``0O``, or ``0x``/``0X``, as with integer literals in code. Base 0
901-
means to interpret exactly as a code literal, so that the actual base is 2,
902-
8, 10, or 16, and so that ``int('010', 0)`` is not legal, while
903-
``int('010')`` is, as well as ``int('010', 8)``.
903+
means to interpret similar to a :ref:`code literal <integers>`, in that the
904+
actual base is 2, 8, 10, or 16 as determined by the prefix. Base 0 also
905+
disallows leading zeros: ``int('010', 0)`` is not legal, while ``int('010')``
906+
and ``int('010', 8)`` are.
904907

905908
The integer type is described in :ref:`typesnumeric`.
906909

0 commit comments

Comments
 (0)