Removing None objects from a sequence

MRAB google at mrabarnett.plus.com
Fri Dec 12 11:45:02 EST 2008


Kirk Strauser wrote:
> At 2008-12-12T15:51:15Z, Marco Mariani <marco at sferacarta.com> writes:
> 
>> Filip Gruszczyński wrote:
>>
>>> I am not doing it, because I need it. I can as well use "if not elem
>>> is None",
> 
>> I suggest "if elem is not None", which is not quite the same.
> 
> So what's the difference exactly?  "foo is not None" is actually surprising
> to me, since "not None" is True.  "0 is True" is False, but "0 is not None"
> is True.  Why is that?
 >
I suppose that it should really be "not is" (cp "not in"), but Guido 
chose to follow the English pattern "is not". "not" returns a Boolean 
(or originally an int) and "is" checks for identity, but the result of 
"is False" or "is True" is down to implementation details in the 
interpreter, so you wouldn't write "is not ..." to mean "is (not ...)" 
anyway, and in practice it's not a problem.



More information about the Python-list mailing list