On 15 June 2013 19:45, eryksun <eryk...@gmail.com> wrote: > On Sat, Jun 15, 2013 at 10:23 PM, eryksun <eryk...@gmail.com> wrote: >> This function is hard coded for the singletons True, >> False, and None -- and otherwise uses either __bool__ >> (tp_as_number->nb_bool) or __len__ (tp_as_mapping->mp_length or >> tp_as_sequence->sq_length). A length of 0 is falsey.
I decided to boil it down to what I could remember easily, so this is the result: ## Comparing different types for equality always fails: if '5' != 5: print('oops') # oops if '' == False: print("This will never print.") ## But: if bool('') == False: print("Now they're the same type and this will print") ## Now they're the same type and this will print ## And the Python documentation says 'not' doesn't give a damn about types ## ## "Because not has to invent a value anyway, it does not bother to return a ## value of the same type as its argument, so e.g., not 'foo' yields False, not ''." ## ## Finally, 1 and 0 are oh-so-special standins for True and False, that should have ## been strangled in the cradle. -- Jim After indictment the bacon smuggler was put on the no-fry list _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor