I want to show someone how using is
instead of ==
to compare integers can fail. I thought this would work, but it didn't:
>>> import copy
>>> x = 1
>>> y = copy.deepcopy(x)
>>> x is y
True
I can do this easily for bigger integers:
>>> x = 500
>>> y = 500
>>> x is y
False
How can I demonstrate the same thing with smaller integers which might typically be used for enum-like purposes in python?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…