How to test if an object IS another object?
Roose
no at spam.com
Sun Jun 12 18:27:18 EDT 2005
This isn't a good example to test with, since 3 is an immutable object, as
is 300 and all ints.
It's more meaningful if the objects are mutable. Why do you want to test
identity in the first place?
Roose
<eloff777 at yahoo.com> wrote in message
news:1118607204.001609.25310 at g47g2000cwa.googlegroups.com...
> Sorry about removing my message, I posted with the wrong google
> account, I don't really want my email where those irritating spam bots
> can find it.
>
>>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? Yet applying the is operator yields True.
>
> Thanks,
> -Dan
>
More information about the Python-list
mailing list