2 ms·
But this is using the seemingly harmless keyword "is" that's you're supposed to use sometimes. A programmer could stumble upon one of these statements and think
by exporectomy 6y ago
But this is using the seemingly harmless keyword "is" that's you're supposed to use sometimes. A programmer could stumble upon one of these statements and think it's going to work reliably after it works the first time.
I used to test for None by doing what seemed to work:
if my_variable:
do something
until I discovered it doesn't work if my_variable = 0 or some other falsy value besides None.
- mannerheim 6y agoYou could use '== None' instead, but it's generally recommended to use 'is None' (supposedly this is slightly faster). I don't think I've ever encountered anything else relying on 'is'. IMO the 'is' keyword was a poor language decision, given how rarely it's ever used.
- mannykannot 6y agoI agree. 'is' creates opportunities for possibly counter-intuitive implementation dependency, for very little gain.