[Tutor] What is the difference between checking false?

Steven D'Aprano steve at pearwood.info
Sun Jun 16 07:38:43 CEST 2013


On 16/06/13 13:15, Jim Mooney wrote:
> ## Comparing different types for equality always fails:
>
> if '5' != 5:
>      print('oops')


Not always. Counter-examples are most obvious when it comes to numbers:

py> from decimal import Decimal
py> from fractions import Fraction
py> Fraction(1, 2) == Decimal("0.5")
True
py> 0.75 == Fraction(3)/4
True
py> 42 == 42.0
True



-- 
Steven


More information about the Tutor mailing list