There exist three numeric types in core Python:
int
: a near-perfect model for whole numbers (i.e., Z); inherently precisefloat
: the "gold" standard to approximate real numbers (i.e., R); inherently imprecisecomplex
: layer on top of the float
type to approximate complex numbers (i.e., C); inherently impreciseFurthermore, the standard library provides two more types that can be used as substitutes for the
float
type:
Decimal
: similar to float
but allows customizing the precision; still inherently impreciseFraction
: a near-perfect model for rational numbers (i.e., Q); built on top of the int
type and therefore inherently preciseThe important takeaways for the data science practitioner are:
nan
results when working with float
numbers as there are no loud failures.The numerical tower is Python's way of implementing various abstract ideas of what numbers are in mathematics.