473,394 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

I just don't get it

Hi All,

Would anyone be so kind to explain this?

-- begin --
(176L,) > 300

True
--end--

(Python2.3)

TIA.

Ed.
Jul 18 '05 #1
5 1274
Try comparing apples and apples:
(176L,) > (300,)

False
Jul 18 '05 #2
* Eduardo Elgueta <ee******@navix.cl> [2004-02-27 16:18]:
Hi All,

Would anyone be so kind to explain this?

-- begin --
(176L,) > 300 True
--end--


Comparing objects of different types (tuple and integer in your
example), while deterministic within a specific python version, puts
them in an arbitrary order.
() > 300 True () > [] True [] > () False 'a' > 300 True 'a' > () False () > 'a' > 300 True [] > 'a' False [] > 300 True () > 'a' > [] > 300 True
So, you probably don't want to be comparing disparate types and
attaching any meaning to the result.

If you wanted to compare the two numbers in your example, you would want
to index the tuple to get at the value inside it:
(176L,) > 300 True (176L,)[0] > 300

False
HTH-

John
< my_first_name AT my_last_name DOT net >

Jul 18 '05 #3
On 27 Feb 2004 15:16:32 -0800, ee******@navix.cl (Eduardo Elgueta)
wrote:
Hi All,

Would anyone be so kind to explain this?

-- begin --
(176L,) > 300

True
--end--

(Python2.3)

TIA.

Ed.


Those are different data types - you are comparing a tuple with a
number. When different data types are compared, Python uses an
arbitrary but consistent ordering. This can be very useful at times,
for example when maintaining and searching a sorted list.

If Python started trying to guess your intentions, and assumed that
you really meant to compare the values, a whole load of quite basic
things wouldn't work. Your example with different numbers may seem
obvious, but what if the numbers were the same? Which of the following
should return true?

(50,) < 50
(50,) == 50
(50,) > 50

If you think the middle one, what if the difference between having a
tuple and a number is important?

If you think that all should return false, you're not going to have
much luck with a lot of standard algorithms - it would violate a basic
assumption about ordering relations.

Personally, I might have gone with 'it makes no sense to compare
different types so raise an exception'. Possibly. But probably not.
Pythons system works very well in practice.
In Python, if you want to compare the actual numbers you need to
compare the actual numbers. It works out better in the long run when
your language isn't always second guessing what it thinks you really
meant.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #4
On Sat, 28 Feb 2004 00:14:29 +0000, Stephen Horne
<st***@ninereeds.fsnet.co.uk> wrote:
If Python started trying to guess your intentions, and assumed that
you really meant to compare the values, a whole load of quite basic
things wouldn't work.


Just thought I'd chuck in a different example of what could happen if
Python started second guessing intentions.

(1,) == 1 .......... the numbers are both 1, after all

(1,) == () ......... maybe you're just checking they're both
tuples, after all?

But then for both those to be true, you also get...

1 == () ............ because 1 == (1,) == ()
2 == () ............ because 2 == (2,) == () by the same logic

1 == 2 ............. because 1 == () == 2
In short, you either have to live with inconsistencies in ordering
relationships that break standard algorithms and lead to all kinds of
unexpected problems in any program over about 100 lines of code, or
you have the ultimate egalitarian society of objects where every
object is equal to every other object, irrespective of value or
anything else.

Neither seems attractive to me.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #5
Stephen and everyone else,

Thank you very much for your answers. I'm not new to Python, but I
still have a long way to go

Ed.

Stephen Horne <st***@ninereeds.fsnet.co.uk> wrote in message news:<mc********************************@4ax.com>. ..
On Sat, 28 Feb 2004 00:14:29 +0000, Stephen Horne
<st***@ninereeds.fsnet.co.uk> wrote:
If Python started trying to guess your intentions, and assumed that
you really meant to compare the values, a whole load of quite basic
things wouldn't work.


Just thought I'd chuck in a different example of what could happen if
Python started second guessing intentions.

(1,) == 1 .......... the numbers are both 1, after all

(1,) == () ......... maybe you're just checking they're both
tuples, after all?

But then for both those to be true, you also get...

1 == () ............ because 1 == (1,) == ()
2 == () ............ because 2 == (2,) == () by the same logic

1 == 2 ............. because 1 == () == 2
In short, you either have to live with inconsistencies in ordering
relationships that break standard algorithms and lead to all kinds of
unexpected problems in any program over about 100 lines of code, or
you have the ultimate egalitarian society of objects where every
object is equal to every other object, irrespective of value or
anything else.

Neither seems attractive to me.

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: Herbert | last post by:
I'm still relativey new to stylesheets, so I'm hoping that the way I'm going about things can be seriously improved upon, i.e . I just haven't undersood something obvious about the 'cascading'...
99
by: Jim Hubbard | last post by:
It seems that Microsoft not only does not need the classic Visual Basic developer army (the largest army of developers the world has ever seen), but now they don't need ANY Windows developer at a...
25
by: Tim | last post by:
Dear Developers, Firstly, I'm not sure where this post should go so I apologise if this is in the wrong group or area. I'm currently interviewing for a vb.net developer who doesn't mind...
16
by: John Rivers | last post by:
http://www.15seconds.com/Issue/030812.htm?voteresult=1 poor guy worked his heart out, just to make a page control and then they published it ha ha ha ha ha to "help" others
19
by: John Salerno | last post by:
Sorry to post here about this again, but the hint forums are dead, and the hints that are already there are absolutely no help (mostly it's just people saying they are stuck, then responding to...
66
by: mensanator | last post by:
Probably just me. I've only been using Access and SQL Server for 12 years, so I'm sure my opinions don't count for anything. I was, nevertheless, looking forward to Sqlite3. And now that gmpy...
20
by: kwikius | last post by:
As I understand it posts to comp.std.c++ shouldnt contain personal attacks. Since several of my posts on this to comp.std.c++ on this subject have now been simply ignored with out any reply by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.