This section covers numbers, strings, lists, dictionaries, tuples, files, and other core built-in types. Compound datatypes (e.g., lists, dictionaries, and tuples) can nest inside each other arbitrarily and as deeply as required. Sets may participate in nesting as well, but may contain only immutable objects.
This section covers basic number types (integers, floating-point), as well as more advanced types (complex, decimals, and fractions). Numbers are always immutable (unchangeable).
Numbers are written in a variety of numeric constant forms.
Integers (unlimited precision)
Floating-point (normally implemented as C doubles in CPython)
Octal, hex, and binary literals for integers
Module-based types: decimal, fraction
Create numbers from other objects, or from strings with possible base conversion; see Built-in Functions
Number types support all number operations (see Table 1-6). In mixed-type expressions, Python converts operands up to the type of the “highest” type, where integer is lower than floating-point, which is lower than complex. As of Python 3.0 and 2.6, integer and floating-point objects also have a handful of methods and other attributes; see Python’s Library Reference manual for details.
>>> (2.5).as_integer_ratio() # float attributes ...