Possible duplicates:
Types for which the keyword is may be equivalent to the equality operator in Python
Python "is" statement behaves unexpectedly with integers
Hey.
I have a question that may perhaps enlighten me more than I ask.
Consider this:
>>> x = 'Hello' >>> y = 'Hello' >>> x == y True >>> x is y True
I have always used the comparison operator. I also read that is compares the memory address and therefore in this case returns True
So my question is: is this another way of comparing variables in Python? If so, why is this not used?
I also noticed that in C ++, if the variables have the same value, their memory addresses are different.
{ int x = 40; int y = 40; cout << &x, &y; } 0xbfe89638, 0xbfe89634
What is the reason that Python has the same memory addresses?
python
user225312
source share