class Temp:
x = 10
def get_settings():
return Temp()
if __name__ == '__main__':
y1 = get_settings()
y2 = get_settings()
z1 = id(get_settings())
z2 = id(get_settings())
if id(y1) == id(y2):
print('Same object y1 and y2')
else:
print('DIFFERENT object y1 and y2 (AS EXPECTED)')
if z1 == z2:
print('SAME object z1 and z2 (WHY???)')
Output:
DIFFERENT object y1 and y2 (AS EXPECTED)
SAME object z1 and z2 (WHY???)
I expected z1 and z2 to be different, but the output suggests that they are id of same object. is this a bug in python? Or am I missing something.