473,387 Members | 1,757 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,387 software developers and data experts.

Curious relation

I was reading the programming Reddit tonight and came across this
(http://reddit.com/info/6gwk1/comments/):
>>([1]>2)==True
True
>>[1]>(2==True)
True
>>[1]>2==True
False

Odd, no?

So, can anyone here shed light on this one?
Jun 27 '08 #1
2 835
On Apr 23, 11:51 pm, Greg J <greg.ja...@gmail.comwrote:
I was reading the programming Reddit tonight and came across this
(http://reddit.com/info/6gwk1/comments/):
>([1]>2)==True
True
>[1]>(2==True)
True
>[1]>2==True

False

Odd, no?

So, can anyone here shed light on this one?
A long time ago, it wasn't possible for comparison operators to raise
exceptions, so it was arbitrarily decided that numbers are less than
strings. Thus, [1]>2 and [1]>False. This explains your first two
examples.

For the third, remember that the comparison operators are chained, so
a>b==c means (a>b) and (b==c). Since 2==True is false, so is the
entire expression.

In Python 3.0, all three of these expressions will raise a TypeError.
Jun 27 '08 #2
On Apr 24, 12:08 am, Dan Bishop <danb...@yahoo.comwrote:
On Apr 23, 11:51 pm, Greg J <greg.ja...@gmail.comwrote:
I was reading the programming Reddit tonight and came across this
(http://reddit.com/info/6gwk1/comments/):
>>([1]>2)==True
True
>>[1]>(2==True)
True
>>[1]>2==True
False
Odd, no?
So, can anyone here shed light on this one?

A long time ago, it wasn't possible for comparison operators to raise
exceptions, so it was arbitrarily decided that numbers are less than
strings. Thus, [1]>2 and [1]>False. This explains your first two
examples.
Sure, those I understood.
For the third, remember that the comparison operators are chained, so
a>b==c means (a>b) and (b==c). Since 2==True is false, so is the
entire expression.
Ach! Of course. For some reason I was blanking on the chained nature
of relational operators in Python.

Thanks for the reminder!
>
In Python 3.0, all three of these expressions will raise a TypeError.
Jun 27 '08 #3

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

Similar topics

0
by: Andreas | last post by:
Hi folks, how would you design a 1:1 relation ? I'd like to split an entities's attributes because they won't get equally frequently requested. So I can save memory and disk access time....
3
by: Terrence Brannon | last post by:
I don't know what Postgres considers a relation and had no intention of creating one when piping my schema to it... I always DROP TABLE before CREATE TABLE, so here are the ERRORS emitted when...
2
by: deko | last post by:
ALTER TABLE DROP CONSTRAINT ; Is this syntax correct? The error I'm getting is: Error Number 3199: Could not find reference. I tried it without the curly braces, but no luck.
6
by: Brian Henry | last post by:
Here's an example of the code.. I have two combo boxes on screen that when one's selection is change the other's items will be updated to reflect the change (based on a relation) Private...
5
by: Corno | last post by:
Hi all, If I want to provide a typed dataset from a webservice and if that dataset has relations that are nested (isNested=True), then the relations(keyrefs) are not available in the XSD that is...
7
by: Juris Krumins | last post by:
I have a problem with postgresql tables. periodicaly, I would say frequently about 5-10 time per hour i have such errors in my server log file: 2004-04-14 12:23:32 ERROR: cache lookup of...
0
by: Ambica Jain | last post by:
I have a data grid called Files, which has some columns like FileName, Col1, Col2, ... , Col8. Then i have a combobox which allows user to select from Col1 to Col8 and based on this selection, i...
1
by: Tim Kelley | last post by:
I have two tables that are linked by 2 fields (ID1 and ID2). Is it possible to create this relation once the tables are in a DataSet? I can create a relation using a single field, but I don't...
4
bugboy
by: bugboy | last post by:
I'm inserting a new word into table 'w' and a definition into table 'c' which are linked in table 's' which is the relation table for the many to many relationship between 'w' and 'c'. I've been...
9
by: Miro | last post by:
VS2008 I have created 3 tables. Vendors Customers PhoneNumbers each have their own key Vendor has: VendorID - int unique identifier Customer has: CustomerID - int unique identifier
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.