2.4.4 整数和长整数型的字面值 Integer and long integer literals

Integer and long integer literals are described by the following lexical definitions:

整数和长整数型字面值可以用以下词法定义:

longinteger  ::=  integer ("l" | "L")
integer  ::=  decimalinteger | octinteger | hexinteger
decimalinteger  ::=  nonzerodigit digit* | "0"
octinteger  ::=  "0" octdigit+
hexinteger  ::=  "0" ("x" | "X") hexdigit+
nonzerodigit  ::=  "1"..."9"
octdigit  ::=  "0"..."7"
hexdigit  ::=  digit | "a"..."f" | "A"..."F"
Download entire grammar as text.

Although both lower case "l" and upper case "L" are allowed as suffix for long integers, it is strongly recommended to always use "L", since the letter "l" looks too much like the digit "1".

虽然小写的"l"的大写的"L"都可以作为长整数的后缀, 但强烈火推荐使用"L", 因为字母"l"看来太像数字1了.

Plain integer literals that are above the largest representable plain integer (e.g., 2147483647 when using 32-bit arithmetic) are accepted as if they were long integers instead.2.1 There is no limit for long integer literals apart from what can be stored in available memory.

普通十进制整数最大可以为2147483647(也就是使用32位比特数字的最大值),普通的八进制和十六进制数可以4294967295, 但大于2147483647的数就通过减4294967295变为负数了.长整数的大小是没有限制的, 仅仅受制于可用的内存容量.

Some examples of plain integer literals (first row) and long integer literals (second and third rows):

下面是一些普通和长整数的例子:

7     2147483647                        0177
3L    79228162514264337593543950336L    0377L   0x100000000L
      79228162514264337593543950336             0xdeadbeef



注脚

... instead.2.1
In versions of Python prior to 2.4, octal and hexadecimal literals in the range just above the largest representable plain integer but below the largest unsigned 32-bit number (on a machine using 32-bit arithmetic), 4294967296, were taken as the negative plain integer obtained by subtracting 4294967296 from their unsigned value.