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

None in comparison

Hello,
I'm a little confused about None in comparison.
>>id ( None )
3086100672L
>>id ( 1 )
134541104
>>None < 1
True
>>>
I thought, the id of the object is the last comparison criterion.
Therefore, None must be greater then 1.
Where is the behaviour of the comparison defined?. In the __cmp__ of
int. Or in the global cmp Function?

Thanks in advance
Rainer
Jul 18 '08 #1
2 1300
On Thu, 17 Jul 2008 23:52:13 -0700, r.grimm wrote:
Hello,
I'm a little confused about None in comparison.
>>>id ( None )
3086100672L
>>>id ( 1 )
134541104
>>>None < 1
True
>>>>

I thought, the id of the object is the last comparison criterion.
Obviously that expectation is false. The result of a comparison between
different types, with no `__cmp__()` method that says otherwise, is a
arbitrarily but consistent ordering by type. The language doesn't even
guarantee that it must be consistent in different runs of the same program
in the same interpreter, just within one run.

So if you plan to rely on such implementation details, your program is
broken.

Ciao,
Marc 'BlackJack' Rintsch
Jul 18 '08 #2


Marc 'BlackJack' Rintsch wrote:
On Thu, 17 Jul 2008 23:52:13 -0700, r.grimm wrote:
>Hello,
I'm a little confused about None in comparison.
>>>>id ( None )
3086100672L
>>>>id ( 1 )
134541104
>>>>None < 1
True
I thought, the id of the object is the last comparison criterion.

Obviously that expectation is false. The result of a comparison between
different types, with no `__cmp__()` method that says otherwise, is a
arbitrarily but consistent ordering by type. The language doesn't even
guarantee that it must be consistent in different runs of the same program
in the same interpreter, just within one run.

So if you plan to rely on such implementation details, your program is
broken.
And in 3.0 such arbitrary comparisons are gone.
>>None < 1
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
None < 1
TypeError: unorderable types: NoneType() < int()

Jul 18 '08 #3

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

Similar topics

8
by: Sam Sungshik Kong | last post by:
Hello! I use Python for ASP programming. I found something weird. Response.Write(Request("something")) It draws "None" when there's no value for something. Actually I expect "" instead of...
18
by: Alan G Isaac | last post by:
>>None >= 0 False True Explanation appreciated. Thanks, Alan Isaac
26
by: Ping | last post by:
Hi, I'm wondering if it is useful to extend the count() method of a list to accept a callable object? What it does should be quite intuitive: count the number of items that the callable returns...
7
by: | last post by:
Hi, I just stumbled upon the following issue (I am running Debian): $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) on linux2 Type "help", "copyright", "credits" or "license" for...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.