Skip to content

Commit af136e9

Browse files
gh-100428: Make int documentation more accurate (GH-100436)
- 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, unicode digits, underscores - 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. (cherry picked from commit edfbf56) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
1 parent e7a2659 commit af136e9

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Diff for: Doc/library/functions.rst

+15-11
Original file line numberDiff line numberDiff line change
@@ -892,17 +892,21 @@ are always available. They are listed here in alphabetical order.
892892
For floating point numbers, this truncates towards zero.
893893

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

907911
The integer type is described in :ref:`typesnumeric`.
908912

0 commit comments

Comments
 (0)