3 ms·
In this particular case, you want to write name is None since None is a unique distinct value edit: didn't notice at first that you wrote an assignment, no
by riquito 13y ago
In this particular case, you want to write
name is None
since None is a unique distinct value
edit: didn't notice at first that you wrote an assignment, not a comparison
- danudey 13y agoNote that 'is' in Python is kind of tricky. None is None, and any value==None is also None. 1 is 1, and 100 is 100; 256 is 256 but 257 is not 257, and "test" is not "test". The reason for this is that 'is' tests to see if both operands are the same object; it's not a test of equivalence on any level. There is only ever one instance of None, and you simply get or create references to it. Likewise, there is only one instance of integers up to 256 (presumably a performance optimization for small loops, indexes, etc.). Integers after 256 get separate instances each time, so 'is' fails after that point. A lot of newcomers to Python come across the 'is None' construct and make assumptions about what 'is' does; the worst part is that they're often correct, and the behaviour becomes difficult to track down when it changes.