Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6817 > unrolled thread
| Started by | Anirudh Sivaraman <sk.anirudh@gmail.com> |
|---|---|
| First post | 2011-06-01 11:50 -0700 |
| Last post | 2011-06-02 03:05 -0700 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.lang.python
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
| From | Anirudh Sivaraman <sk.anirudh@gmail.com> |
|---|---|
| Date | 2011-06-01 11:50 -0700 |
| Subject | Comparison operators in Python |
| Message-ID | <0dda7cc8-e1c0-409d-b993-b8aec379f7bd@hd10g2000vbb.googlegroups.com> |
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 ? Anirudh
[toc] | [next] | [standalone]
| From | Jussi Piitulainen <jpiitula@ling.helsinki.fi> |
|---|---|
| Date | 2011-06-01 22:08 +0300 |
| Message-ID | <qotd3ixjrnm.fsf@ruuvi.it.helsinki.fi> |
| In reply to | #6817 |
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()
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2011-06-01 13:16 -0600 |
| Message-ID | <mailman.2378.1306955816.9059.python-list@python.org> |
| In reply to | #6817 |
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
[toc] | [prev] | [next] | [standalone]
| From | harrismh777 <harrismh777@charter.net> |
|---|---|
| Date | 2011-06-01 19:44 -0500 |
| Message-ID | <62BFp.19321$pi2.14587@newsfe11.iad> |
| In reply to | #6819 |
Ian Kelly wrote:
>> 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:
>
Just another example (excluding print 1/2 and unicode) where 3.x
seems to be completely compatible with 2.x/ (tongue-in-cheek)
(do Brits say tongue-in-cheek?)
:)
... just saying.
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2011-06-02 02:09 -0400 |
| Message-ID | <mailman.2382.1306994970.9059.python-list@python.org> |
| In reply to | #6829 |
On 6/1/2011 8:44 PM, harrismh777 wrote: > Ian Kelly wrote: >> ?? wrote >>> 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: This was a Python 1.0 idea that Guido decided was more bug-inducing than useful. > Just another example (excluding print 1/2 and unicode) where 3.x seems > to be completely compatible with 2.x/ (tongue-in-cheek) Arbitrary comparisons were broken and effectively deprecated about a decade ago with the introduction of the complex type. Just another example where 3.x completes a process of change started years before. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Michael Sparks <sparks.m@gmail.com> |
|---|---|
| Date | 2011-06-02 03:05 -0700 |
| Message-ID | <6a057294-8dde-4f46-ac4d-e00c5de26c4d@x10g2000yqj.googlegroups.com> |
| In reply to | #6829 |
On Jun 2, 1:44 am, harrismh777 <harrismh...@charter.net> wrote: .. > Just another example (excluding print 1/2 and unicode) where 3.x > seems to be completely compatible with 2.x/ (tongue-in-cheek) One of the key purposes of the 3.x line of code is to get rid of warts in the language. As a result, if someone is relying on warts, then their code will break when changing from 2.x to 3.x. IMO, this is actually a good thing since it encourages the reduction in warty code. (People who want to use 2.x and 3.x can either use 2to3 and maintain 2to3-able code or write code that works in both 2.x and 3.x - which is eminently doable) > (do Brits say tongue-in-cheek?) Yes. Michael.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web