easy question on parsing python: "is not None"

Stefan Schwarzer sschwarzer at sschwarzer.net
Sat Aug 7 09:04:06 CEST 2010


Hi Steven,

On 2010-08-07 00:28, Steven D'Aprano wrote:
> On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote:
>>> Plus, I believe the
>>> "==" operator will check if the variables point to the same object.
>>
>> No, that's what `is` is for.
> 
> Actually, yes, equality is implemented with a short-cut that checks for 
> identity first. That makes something like:
> [...]

Oops, I didn't realize that the OP had mentioned the
identity check as an optimization in case the objects are
the same. I thought he was confusing the operator with `is`.

> s = "abc"*1000*1000*10
> s == s
> 
> nice and quick, as Python can immediately recognise that a string is 
> always equal to itself without having to walk the entire string comparing 
> each character with itself.

Yes, that definitely makes sense. I guess I would have
implemented it this way as well. :)

Stefan



More information about the Python-list mailing list