float(1.0) is float(1.0) #True
float(1) is float(1) #False
I've isolated the float() oddity here to the object creation order, because
x1 = float(1)
x2 = float(1)
x1 is x2 #False
id(x1) == id(x2) #False
y1 = float(1.0)
y2 = float(1.0)
y1 is y2 #True
id(y1) == id(y2) #True
Note: I've done checks on the precision of the floats and it is not the reason why this is happening.
I wish to understand why and how is Python deciding to create float objects. Why is float(1.0) pointing to the same object while float(1) points to 2 different objects when either are created twice?
Also, for further reference:
float(1) is float(1) #False
id(float(1)) == id(float(1)) #True
float(1.0) is float(1.0) #True
id(float(1.0)) == id(float(1.0)) #True