4

I always thought operator is determined if the given variable is of the given type. But I just determined it was not true:

>>> class A():
      pass
... 
>>> a = A()
>>> a is A
False

How do I test if a is of type class A?

Please advise.

Thanks, Boda Cydo.

1
  • 2
    it seems like with every newbie a wave of duplicates overwhelms SO. you just have to look to your right if you have any doubt. Commented Mar 11, 2010 at 22:28

2 Answers 2

7

You want isinstance(a, A).

Keep in mind, it might be better to avoid the isinstance check by adding methods to A that make it do what you want without explicitly determining that it is an A.

is determines if two objects are the same object.

Sign up to request clarification or add additional context in comments.

1 Comment

Adding to what Ned correctly mentioned, a is b is the same as doing id(a) == id(b)
2

isinstance(a,A)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.