Glossary

Integer

Also known as: int

The int type in Python represents whole numbers — positive, negative, or zero — with arbitrary precision. Unlike C or Java, where integers overflow at 32 or 64 bits, Python integers grow as large as available memory permits. You can compute 2 ** 10000 and get an exact result. This arbitrary precision is implemented in CPython using an array of "digits" (each typically 30 bits) under the hood.

Integers support all the standard arithmetic operations: addition, subtraction, multiplication, floor division (//), true division (/, which returns a float), modulo (%), and exponentiation (**). The divmod() built-in returns both quotient and remainder simultaneously. Integers also support bitwise operations (&, |, ^, ~, <<, >>), which makes them useful for flags and low-level protocols.

Small integers in the range roughly -5 to 256 are cached by CPython as a performance optimisation — the same object is reused wherever that value appears. This is an implementation detail, not a language guarantee, so you should always compare integers with == (equality) rather than is (identity). Integers are immutable: operations always create a new integer object rather than modifying the original.

Related terms: Float, Immutable, Boolean

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.