Christian Heimes wrote:
You are getting the result because Python optimized small integers.
See http://svn.python.org/projects/pytho...ts/intobject.c
Integers between -5 and +256 are singletons as are some other objects
like strings with one element or empty tuples. You must not rely on
the optimization.
i see now, so i guess that's also why id() returns the same address for
them as well...
i'll dive into the implementation file, it may be a bit out of my league
but i'll see what i can gather, and hey, that's how it works, right? :-)
thanks
ariel 5 2361
On Thu, 14 Aug 2008 18:23:21 -0300, ariel ledesma wrote:
i see now, so i guess that's also why id() returns the same address for
them as well...
It just have to work like this.
a is b
is actually equal to:
id(a) == id(b)
so there is no other way for id() in such case.
Hope this helps.
--
Regards,
Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/
On Aug 14, 4:31*pm, Wojtek Walczak <gmin...@bzt.bztwrote:
On Thu, 14 Aug 2008 18:23:21 -0300, ariel ledesma wrote:
i see now, so i guess that's also why id() returns the same address for
them as well...
It just have to work like this.
a is b
is actually equal to:
id(a) == id(b)
so there is no other way for id() in such case.
Hope this helps.
--
Regards,
Wojtek Walczak,http://www.stud.umk.pl/~wojtekwa/
For
a= 6
b= a
the test
a is b
should clearly return true. Python distinguishes what mathematics
does not, between identity and equality. Clearly 5+4 and 6+3 -
evaluate- to the same, but math doesn't define whether they are the
same, and in some sense the question isn't asked ordinarily, or isn't
debated. I want to infer that math doesn't define the 'is' relation
as Python knows it.
I feel the documentation should state, 'the interpreter is free to
return a -new- equivalent non-identical object in the case of
immutables.'
My tests:
>>a= -6 a is -6
False
>>-6 is -6
True
I don't know a convincing argument for the truth of Is( -6, -6 ).
Perhaps you could make one, or one for the permissibility of Is( a,
b ) & ~Equal( a, b )... identical non-equivalent.
On Thu, 14 Aug 2008 20:44:32 -0700, castironpi wrote:
For
a= 6
b= a
the test
a is b
should clearly return true.
Since Python promises not to make a copy of a when you execute "b = a",
then I think that such behaviour is guaranteed by the language.
Python distinguishes what mathematics does
not, between identity and equality. Clearly 5+4 and 6+3 - evaluate- to
the same, but math doesn't define whether they are the same, and in some
sense the question isn't asked ordinarily, or isn't debated. I want to
infer that math doesn't define the 'is' relation as Python knows it.
Mathematicians often *define* equality as identity. That certainly makes
sense when dealing with numbers -- what would it mean to say that there
are (say) three different instances of the abstract integer 42, all equal
yet not identical? I suggest that this simply doesn't make sense -- it is
"not even wrong".
Equality-as-identity may not hold in all areas of mathematics, but I
think it is safe to say it holds for ideal (abstract) numbers, as opposed
to implementations of numbers as bit patterns or objects in memory. http://en.wikipedia.org/wiki/Equality_(mathematics)
--
Steven
well, i'm glad i stumbled upon this detail early on (i only had to fix
about one page of code)... i'll just stick to 'is' when it concerns
checking if it is the *same* object (memorywise) instead of an
*equivalent* one...
just before wrapping up, the special methods __eq__ and __ne__ are
called upon == and !=, right? not for 'is', 'is not'...
Steven D'Aprano wrote:
>
Mathematicians often *define* equality as identity. That certainly makes
sense when dealing with numbers -- what would it mean to say that there
are (say) three different instances of the abstract integer 42, all equal
yet not identical? I suggest that this simply doesn't make sense -- it is
"not even wrong".
Equality-as-identity may not hold in all areas of mathematics, but I
think it is safe to say it holds for ideal (abstract) numbers, as opposed
to implementations of numbers as bit patterns or objects in memory.
http://en.wikipedia.org/wiki/Equality_(mathematics)
but who knows? maybe abstract numbers -5 to 256 are optimized as well! :-)
ariel ledesma wrote:
well, i'm glad i stumbled upon this detail early on (i only had to fix
about one page of code)... i'll just stick to 'is' when it concerns
checking if it is the *same* object (memorywise) instead of an
*equivalent* one...
just before wrapping up, the special methods __eq__ and __ne__ are
called upon == and !=, right? not for 'is', 'is not'...
Correct! You can't change the identity operator 'is' with a magic method.
Christian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pj |
last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter
whether they are truly positive or negative ?
I am having to cast each column to varchar to find out if there are
any...
|
by: Subrahmanyam Arya |
last post by:
Hi Folks ,
I am trying to solve the problem of reading the numbers correctly
from a serial line into an intel pentium processor machine .
I am reading 1 byte and 2byte data both positive...
|
by: John |
last post by:
Hi,
I encountered a strange problem while debugging C code for a
Windows-based application in LabWindows CVI V5.5, which led me to
write the test code below. I tried this code with a different...
|
by: jaks.maths |
last post by:
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
|
by: drtimhill |
last post by:
I'm just starting out on Python, and am stumped by what appears an oddity in the way negative indices are handled.
For example, to get the last character in a string, I can enter "x". To get the...
|
by: Frederick Gotham |
last post by:
I have a general idea about how negative number systems work, but I'd
appreciate some clarification if anyone would be willing to help me.
Let's assume we're working with an 8-Bit signed integer,...
|
by: Hallvard B Furuseth |
last post by:
As far as I can tell, (x & -1) is nonzero if the integer x is
negative zero. So for signed types, x == 0 does not guarantee
(x & foo) == 0. Is that right? (Not that I expect to ever
encounter a...
|
by: Casey |
last post by:
Is there an easy way to use getopt and still allow negative numbers as
args? I can easily write a workaround (pre-process the tail end of
the arguments, stripping off any non-options including...
|
by: ariel ledesma |
last post by:
hello guys
i just ran into this when comparing negative numbers, they start
returning False from -6 down, but only when comparing with 'is'
True
False
True
i read that 'is' compares if...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |