Comparing 2 class types
Aahz Maruch
aahz at netcom.com
Fri Jul 7 11:56:09 EDT 2000
In article <L2k95.37383$NP5.1176274 at newsread2.prod.itd.earthlink.net>,
Arinté <shouldbe at message.com> wrote:
>
>How can you know if a 2 variables are different instances of the same class?
>x = someclass()
>y= someclass()
>I tried is, type, and type(x) is someclass, but none seem to work unless I
>did it wrong.
In addition to Jepler and Jeremy's responses, you need to also use "is"
to find out whether it's a *different* instance of the same class:
class foo:
pass
a = foo()
b = foo()
c = a
print a is b
print a is c
--
--- Aahz (Copyright 2000 by aahz at netcom.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
"do you want my self-identities alphabetically, chronologically, or in
random order?" -- Misha
More information about the Python-list
mailing list