On Thu, Jul 16, 2009 at 11:13 PM, koranthala<koranth...@gmail.com> wrote: >> That test was designed to treat None as a boolean False, without >> noticing that numeric 0 is also treated as False and could make the >> test do the wrong thing. This is an extremely common type of error. > > Actually, I felt that 0 not being considered False would be a better > option. > I had lot of instances where 0 is a valid value and always I had to > put checks specifically for that. > For me, None and False should be equal to False in if checks, every > thing else being considered True. > > Can someone let me know why 0 is considered equal to False? > There should be real good reasons for it, only that I cannot think of > one.
* Because that's how C does/did it (primary motivation) - Because if Boolean algebra is implemented using numbers, False is 0 - Because philosophically, 0 is the "empty" or null value for numbers, and empty values are by convention considered false in Python - Because it's the behavior people want 75% of the time. FWIW, your paradigm of true/false is used by Lisp and Lisp wannabes such as Ruby. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list