Skip to content Skip to sidebar Skip to footer

How Can I Check If A Type Is A Subtype Of A Type In Python?

How can I check if a type is a subtype of a type in Python? I am not referring to instances of a type, but comparing type instances themselves. For example: class A(object):

Solution 1:

Maybe issubclass?

>>> class A(object): pass
>>> class B(A): pass
>>> class C(object): pass
>>> issubclass(A, A)
True
>>> issubclass(B, A)
True
>>> issubclass(C, A)
False

Post a Comment for "How Can I Check If A Type Is A Subtype Of A Type In Python?"