'20' <= 100

Gerhard Häring gh at ghaering.de
Thu May 1 18:22:25 EDT 2003


Dave Brueck wrote:
> [...] Put another way, if you give Python:
> 
> s = '20'
> t = 2
> x = s * t
> 
> How can it know that you expected 40 instead of '2020'?

Sure, but if you give Pyhthon:

s = '20'
t = 2
if s < 6:
	...

like the OP did, Python should tempt the tempation to guess, like it 
usually does. The comparison operators should IMO be changed to raise a 
TypeError in this case.

strings should only be comparable to other basestrings and numbers 
should only be comparable to other number types.

Does anyone disagree? Why?

-- Gerhard





More information about the Python-list mailing list