Comparison operators in Python

Jussi Piitulainen jpiitula at ling.helsinki.fi
Wed Jun 1 15:08:45 EDT 2011


Anirudh Sivaraman writes:

> I am a relative new comer to Python. I see that typing is strongly
> enforced in the sense you can't concatenate or add a string and an
> integer. However comparison between a string and an integer seems to
> be permitted. Is there any rationale behind this ?

In Python 3 it is an error.

Python 3.1.1 (r311:74480, Feb  8 2010, 14:06:51) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3 < 'kolme'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < str()



More information about the Python-list mailing list