On Feb 19, 1:47 pm, Boris Borcic <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle wrote:
> > On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote:
> > print float(3.0) is float(3.0)
> >> True
> > print float(3.0 * 1.0) is float(3.0)
> >> False
>
> > [You don't need to wrap your floats in floa
Christian Heimes <[EMAIL PROTECTED]> writes:
> >>> id(2000)
> 3084440752
> >>> id(2001)
> 3084440752
Python 2.4.4 (#1, Oct 23 2006, 13:58:00)
>>> id(2000)
155211416
>>> id(2001)
155211416
>>> id(2000) == id(2001)
False
>From the docs:
id( object) Return the ``ide
Asun Friere wrote:
> So was that a yes or no? I mean is it even possible for the identity
> behaviour of mutables to vary between implementations? I can't see
> how they can possibly be interned, but is there some other factor I'm
> missing in regard to identity behaviour which could in fact vary
Steven D'Aprano wrote:
> "is" is a comparison operator: it compares identity, not equality. It is
> more or less equivalent to the expression id(x) == id(y).
Yes, the implementation of the is operator comes down to the comparison
of PyObject* pointer addresses and in CPython id() returns the addr
Duncan Booth wrote:
> Boris Borcic <[EMAIL PROTECTED]> wrote:
>> Arnaud Delobelle wrote:
>>> Whereas when "3.0*1.0 is 3.0" is evaluated, *two* different float
>>> objects are put on the stack and compared (LOAD_CONST 3 / LOAD_CONST
>>> 1 / COMPARE_OP 8). Therefore the result is False.
>> Looks goo
Boris Borcic <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle wrote:
>> Whereas when "3.0*1.0 is 3.0" is evaluated, *two* different float
>> objects are put on the stack and compared (LOAD_CONST 3 / LOAD_CONST
>> 1 / COMPARE_OP 8). Therefore the result is False.
>
> Looks good, but doesn't pass the
Arnaud Delobelle wrote:
> On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote:
> print float(3.0) is float(3.0)
>> True
> print float(3.0 * 1.0) is float(3.0)
>> False
>
> [You don't need to wrap your floats in float()]
>
def f():
> ... return 3.0 is 3.0, 3.0*1.0 is 3.0
> ...
>
"Asun Friere" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| So was that a yes or no? I mean is it even possible for the identity
| behaviour of mutables to vary between implementations? I can't see
| how they can possibly be interned, but is there some other factor I'm
| missing
On Feb 19, 1:45 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> "Asun Friere" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> | The advice not to identity test strings and numbers (since they are
> | interred in the main implementation),
>
> They may or may not be.
Obviously, and
"Asun Friere" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| On Feb 19, 9:44 am, Steven D'Aprano <[EMAIL PROTECTED]
| cybersource.com.au> wrote:
|
| > Except for documented singletons such as modules and None, which
objects
| > have the same identity is platform dependent, version
On Feb 19, 9:44 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> Except for documented singletons such as modules and None, which objects
> have the same identity is platform dependent, version dependent, and even
> dependent on the execution history of your code.
The advice no
On Feb 19, 12:27 pm, Asun Friere <[EMAIL PROTECTED]> wrote:
> But given the nature of immutables
I meant to write "given the nature of mutables" of course ... :/
--
http://mail.python.org/mailman/listinfo/python-list
On Feb 19, 9:44 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> Except for documented singletons such as modules and None, which objects
> have the same identity is platform dependent, version dependent, and even
> dependent on the execution history of your code.
The advice no
On Mon, 18 Feb 2008 14:11:53 +0100, Christian Heimes wrote:
> Tobiah wrote:
> print float(3.0) is float(3.0)
>> True
> print float(3.0 * 1.0) is float(3.0)
>> False
>
>
> Thumb rule: Never compare strings, numbers or tuples with "is". Only
> compare an object with a singl
Tobiah wrote:
print float(3.0) is float(3.0)
> True
print float(3.0 * 1.0) is float(3.0)
> False
It's implementation dependent what values these expressions will take.
If you're trying to test equality, use `==`, not `is`.
--
Erik Max Francis && [EMAIL PROTECTED] && http://
Tobiah wrote:
print float(3.0) is float(3.0)
> True
print float(3.0 * 1.0) is float(3.0)
> False
Thumb rule: Never compare strings, numbers or tuples with "is". Only
compare an object with a singleton like a type or None. "is" is not a
comparison operator.
Christian
--
http:
Tobiah <[EMAIL PROTECTED]> wrote:
> Subject: Seemingly odd 'is' comparison.
Please put your question into the body of the message, not just the
headers.
>>>> print float(3.0) is float(3.0)
> True
>>>> print float(3.0 * 1.0) is float(3.0)
> Fa
On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote:
> >>> print float(3.0) is float(3.0)
> True
> >>> print float(3.0 * 1.0) is float(3.0)
> False
[You don't need to wrap your floats in float()]
>>> def f():
... return 3.0 is 3.0, 3.0*1.0 is 3.0
...
>>> f()
(True, False)
>>> import dis
>>>
>>> print float(3.0) is float(3.0)
True
>>> print float(3.0 * 1.0) is float(3.0)
False
>>>
Thanks,
Tobiah
--
Posted via a free Usenet account from http://www.teranews.com
--
http://mail.python.org/mailman/listinfo/python-list
19 matches
Mail list logo