easy question on parsing python: "is not None"
davea at ieee.org
Mon Aug 9 16:21:38 CEST 2010
> On Aug 9, 3:41 pm, "saeed.gnu" <saeed.... at gmail.com> wrote:
>> "x is y" means "id(y) =id(y)"
>> "x is not y" means "id(x) !=d(x)"
>> "x is not None" means "id(x) !=d(None)"
>> "x is not None" is a really silly statement!! because id(None) and id
>> of any constant object is not predictable! I don't know whay people
>> use "is" instead of "=. you should write "if x!=None" instead of "x
>> is not None"
> Although small objects are unique in the memory (with a unique id) and
> using "is" works ok, but that's not logical to compare id's when we
> actually want to compare values!
None is a single object; there is only one such object by language
definition. So 'is' is the perfect operator if you want to check
whether a particular object is that one or not. All other objects, of
any possible type, will have a different ID than None.
And talking about comparing values is nonsense anyway, since None has no
value. It's only purpose is to indicate that some operation had no
value, or no return statement, or ...
Using '==' will not necessarily give the same result, and I can't think
of ANY case where I'd prefer the former. If you disagree, give a
More information about the Python-list