September 2026
1051 pages
35h 4m
English
Numeric data types can be converted into each other using the int, float, bool, and complex built-in functions. Note that in the process, information can be lost depending on the transformation. As an example, let's consider some conversions in interactive mode:
>>> float(33) 33.0>>> int(33.5) 33>>> bool(12) True>>> complex(True) (1+0j)
Instead of a concrete literal, a reference can be used or a reference can be linked to the resulting value:
>>> var1 = 12.5>>> int(var1) 12>>> var2 = int(40.25) >>> var240
The complex data type assumes a special role in the conversions presented here as it can’t be reduced to a single numerical value in a meaningful way. For this reason, a conversion such ...
Read now
Unlock full access