[Tutor] What is the difference between checking false?
eryksun
eryksun at gmail.com
Sun Jun 16 10:46:57 CEST 2013
On Sat, Jun 15, 2013 at 11:15 PM, Jim Mooney <cybervigilante at gmail.com> wrote:
>
> ## Comparing different types for equality always fails:
>
> if '5' != 5:
> print('oops')
It depends on the __eq__ and __ne__ methods defined by the types. int
and str have their own implementations of "rich comparisons". But
that's a subject for another thread and another time, when you've
gotten deeper into implementing your own classes.
> Finally, 1 and 0 are oh-so-special standins for True and False,
> that should have been strangled in the cradle.
As I already said, you can't return an int from __bool__ in 3.x. In
2.x, __nonzero__ can return 0 for False and a "non-zero" int for True
-- but only an int (not long, float, etc).
More information about the Tutor
mailing list