4 ms·
>>> a = 100; b = 100; print (a is b) True >>> a = 1000; b = 1000; print (a is b) True >>> a = 1000 >>> b = 1000 >>> print (a is b) False Python has its
by dtf 15y ago
>>> a = 100; b = 100; print (a is b)
True
>>> a = 1000; b = 1000; print (a is b)
True
>>> a = 1000
>>> b = 1000
>>> print (a is b)
False
Python has its quirks too. Most people learn them and get over it.
- zeemonkee 15y agoThis might be a good explanation for this behavior: http://stackoverflow.com/questions/2858603/why-is-keyword-has-different-behavior-when-there-is-dot-in-the-string http://stackoverflow.com/questions/2858603/why-is-keyword-ha... tl;dr; use "is" only with singetons (None etc)
- sneak 15y agoI have never once used the 'is' keyword in python.
- dtf 15y agoHave you ever tested for a None value? if foo is None: return if bar is not None: bar()