On 01/-10/-28163 02:59 PM, Joel Goldstick wrote:
2011/3/19 Yaşar Arabacı
a=5
b=5
a == b
True
a is b
True
My question is, why "a is b" is true. What I expected it to be is that, a
and b are different things with same value.
___
Tutor maillist -
This is a special feature called interning in python. As of Python 2.6,
values of -5 to 105 are never cleared from memory for performance reasons.
This is applicable to integers only.
"==" is a value comparator, whereas "is" is a reference compartor.
Check this interesting extension to your code:
2011/3/19 Yaşar Arabacı :
a=5
b=5
a == b
> True
a is b
> True
>
> My question is, why "a is b" is true. What I expected it to be is that, a
> and b are different things with same value.
>
It's an optimization thing. When you type "a=5," the python
interpreter is obligated to give y
On Saturday 2011 March 19 08:35, Emmanuel Ruellan wrote:
> 2011/3/19 Yaşar Arabacı
>
> > >>>a=5
> > >>>b=5
> > >>>a == b
> >
> > True
> >
> > >>>a is b
> >
> > True
> >
> > My question is, why "a is b" is true. What I expected it to be is that, a
> > and b are different things with same value.
>
>
2011/3/19 Yaşar Arabacı
>
>
> >>>a=5
> >>>b=5
> >>>a == b
> True
> >>>a is b
> True
>
> My question is, why "a is b" is true. What I expected it to be is that, a
> and b are different things with same value.
>
Even stranger:
>>> a = 10**10
>>> b = 10**10
>>> a == b
True
>>> a is b
False
>>> a =
2011/3/19 Yaşar Arabacı
> >>>a=5
> >>>b=5
> >>>a == b
> True
> >>>a is b
> True
>
> My question is, why "a is b" is true. What I expected it to be is that, a
> and b are different things with same value.
>
> ___
> Tutor maillist - Tutor@python.org
> T
2011/3/19 Yaşar Arabacı
> >>>a=5
> >>>b=5
> >>>a == b
> True
> >>>a is b
> True
>
> My question is, why "a is b" is true. What I expected it to be is that, a
> and b are different things with same value.
>
> ___
> Tutor maillist - Tutor@python.org
> T
>>>a=5
>>>b=5
>>>a == b
True
>>>a is b
True
My question is, why "a is b" is true. What I expected it to be is that,
a and b are different things with same value.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
h