3.2.2. Arithmetic operations between integers and floats#
When we perform operation between different types, Python may automatically convert integers to floats to ensure that the result holds the correct value. For example, adding an integer to another integer results in an integer:
a = 2 + 4
type(a)
int
However, adding a float to an integer results in a float:
b = 2 + 4.5
type(b)
float
A special case is the division, which always results in a float, even if we divide two integers, and even if the result is round:
c = 4 / 2
type(c)
float