How to test if an object IS another object?
Grant Edwards
grante at visi.com
Sun Jun 12 17:33:03 EDT 2005
On 2005-06-12, eloff777 at yahoo.com <eloff777 at yahoo.com> wrote:
>>The most obvious way (as usual ?):
>>
>>if obj1 is obj2:
>> // your code here
>
> I immediately thought of is, and tested it in the console, but it
> didn't work quite like I expected:
>
>>foo = 3
>>bar = 3
>>zoo = foo
>>foo is zoo
> True
>>foo is bar
> True
>>zoo is bar
> True
>
> clearly foo and bar have the same value but they are different objects
> aren't they?
Nope.
> Yet applying the is operator yields True.
They're the same object. Why did you expect them not to be?
--
Grant Edwards grante Yow! Am I elected yet?
at
visi.com
More information about the Python-list
mailing list