Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6819

Re: Comparison operators in Python

References <0dda7cc8-e1c0-409d-b993-b8aec379f7bd@hd10g2000vbb.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-06-01 13:16 -0600
Subject Re: Comparison operators in Python
Newsgroups comp.lang.python
Message-ID <mailman.2378.1306955816.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jun 1, 2011 at 12:50 PM, Anirudh Sivaraman <sk.anirudh@gmail.com> wrote:
> Hi
>
> 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 ?

It allows things like sorting of heterogeneous lists.  It's generally
viewed as a wart, though, and it was fixed in Python 3:

Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 'x' < 5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()

Cheers,
Ian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Comparison operators in Python Anirudh Sivaraman <sk.anirudh@gmail.com> - 2011-06-01 11:50 -0700
  Re: Comparison operators in Python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-06-01 22:08 +0300
  Re: Comparison operators in Python Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-01 13:16 -0600
    Re: Comparison operators in Python harrismh777 <harrismh777@charter.net> - 2011-06-01 19:44 -0500
      Re: Comparison operators in Python Terry Reedy <tjreedy@udel.edu> - 2011-06-02 02:09 -0400
      Re: Comparison operators in Python Michael Sparks <sparks.m@gmail.com> - 2011-06-02 03:05 -0700

csiph-web