At some point, you will have to work with numbers, so we start by considering different forms of numeric types in Python. In mathematics, we distinguish between natural numbers (ℕ), integers (ℤ), rational numbers (ℚ), real numbers (ℝ) and complex numbers (ℂ). These are infinite sets of numbers. Operations differ between these sets and may even not be defined. For example, the usual division of two numbers in ℤ might not result in an integer — it is not defined on ℤ.
In Python, like many other computer languages, we have numeric types:
- The numeric type
int
, which is at least theoretically the entire ℤ - The numeric type
float
, which is a finite subset of ℝ and - The numeric type
complex
, which is a finite subset of ℂ
Finite sets have a smallest and a largest number and there is a minimum spacing between two numbers; refer to the section on Floating Point Representation for further details.