Common Python Idioms

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Thu Dec 7 17:45:14 EST 2006


On Thu, 07 Dec 2006 13:52:33 -0800, George Sakkis wrote:

> I'm surprized that none of these pages mentions the incompatible type
> comparison gotcha:
> 
>>>> 5 < "4"
> True
> 
> I'm sure this has bitten many folks, particularly (ex) Perl'ers.

Why is this a gotcha? 

I can't speak for others, but except for sorting, I've never been tempted
to compare ints to strings like that, but thinking about the code I've
written, I can't think of any bad consequences that would have happened if
I had.

I'm not saying that there are never bad consequences for comparing
incompatible types, but I'm questioning that it is a gotcha, let alone a
common gotcha. What do others think? Ever been bitten by 5 < "4"?



-- 
Steven.




More information about the Python-list mailing list