a = 2
b = 2
c = 3.5
d = 3.5
e = 2.3 + 1.5j
f = 2.3 + 1.5j
print('id(a) = ', id(a), 'id(b) = ', id(b))
print('id(c) = ', id(c), 'id(d) = ', id(d))
print('id(e) = ', id(e), 'id(f) = ', id(f))
The program shows the follow answer:
id(a) = 10914528 id(b) = 10914528
id(c) = 140295268467240 id(d) = 140295268467240
id(e) = 140295244785552 id(f) = 140295244784464
So a
and b
are two names for the same integer object, and c
and d
are two names for the same float object. But e
and f
are two different objects in CPython. Why?