question about True values

John Coleman jcoleman at franciscan.edu
Wed Oct 25 15:35:34 EDT 2006


Paul Rubin wrote:
> "John Coleman" <jcoleman at franciscan.edu> writes:
> > > then "x == 3" is false, but "int(x) == 3" is true.
> > But then why is 3.0 == 3 true? They are different types.
>
> The 3 gets converted to float, like when you say
>
>   x = 3.1 + 3
>
> the result is 6.1.

Yes - it just seems that there isn't a principled reason for implicitly
converting 3 to 3.0 in 3.0 == 3 but not implicitly converting "cat" to
boolean in "cat" == true. There is something to be said about SML's
rigourous approach where 3.0 = 3 isn't even allowed since it is
considered ill-typed. Nevertheless, it is doubtlessly convientent to be
able to compare integers and doubles directly in the natural way and
there is little practical reason to compare a string with a truth value
so Python's solution does have common sense on its side.




More information about the Python-list mailing list