Difference between 'is' and '=='

Antoon Pardon apardon at forel.vub.ac.be
Tue Mar 28 09:45:09 CEST 2006


Op 2006-03-27, Donn Cave schreef <donn at u.washington.edu>:
> In article <48q9pfFlc8q0U1 at uni-berlin.de>,
>  "Diez B. Roggisch" <deets at nospam.web.de> wrote:
> ...
>> So - your conclusion is basically right: use is on (complex) objects, not on
>> numbers and strings and other built-ins. The exception from the rule is
>> None - that should only exist once, so
>> 
>> foo is not None
>> 
>> is considered better style than foo == None.
>
> But even better style is just `foo' or `not foo'.  Or not,
> depending on what you're thinking.

No it is not. When you need None to be treated special,
that doesn't imply you want to treat zero numbers or empty
sequences as special too.

-- 
Antoon Pardon



More information about the Python-list mailing list