[Tutor] if n == 0 vs if not n
sander.sweers at gmail.com
Thu Oct 8 23:02:27 CEST 2009
On Thu, 2009-10-08 at 12:58 -0700, wesley chun wrote:
> wow, as the OP, you must have been surprised to see how far we have
> taken your (seemingly) simple question.
Pleasently suprised :-) And I am gratefull to see the heavy weights join
> however, what i did *not* mention is that these (abbreviated)
> comparisons do not work should you care to distinguish between
> multiple Python objects/values that have the same boolean value. in
> other words, "if not b" will catch False, None, 0, etc. if your
> application is using 3 values like None (for unset value), False
> (bad/errror code), and True (correct behavior), then None and False
> will both cause the if clause to be executed. in other words, if you
> care about the actual objects, then you need to use either "==" or
> "is", rather than just checking their boolean outcomes.
Good one, I have to remember this as it will very likely bite me
I really appriciate all the feedback and good advice!
More information about the Tutor