Next / Previous / Contents / TCC Help System / NM Tech homepage

7.1. Type int: Integers

Python values of type int represent integers, that is, whole numbers in the range [-231, 231-1], roughly plus or minus two billion.

You can represent a value in octal (base 8) by preceding it with “0o”. Similarly, use a leading “0x” to represent a value in hexadecimal (base 16), or “0b” for binary. Examples in conversational mode:

>>> 999+1
1000
>>> 0o77
63
>>> 0xff
255
>>> 0b1001
9

Note

The 0o and 0b prefixes work only in Python versions 2.6 and later. In 2.5 and earlier versions, any number starting with “0” was considered to be octal. This functionality is retained in the 2.6+ versions, but will not work in the Python 3.x versions.

To convert other numbers or character strings to type int, see Section 20.19, “int(): Convert to int type”.

If you perform operations on int values that result in numbers that are too large, Python automatically converts them to long type; see Section 7.2, “Type long: Extended-precision integers”.