Next / Previous / Contents / TCC Help System / NM Tech homepage

21.13. issubclass(): Is a class a subclass of some other class?

To test whether some class C1 is a subclass of another class C2, use this predicate:

issubclass(C1, C2)

Examples:

>>> class Polygon:
...     pass
... 
>>> class Square(Polygon):
...     pass
... 
>>> issubclass(Square, Polygon)
True
>>> issubclass(Polygon, Square)
False
>>> issubclass(Square, Square)
True
>>> issubclass(unicode, basestring)
True
>>> issubclass(str, basestring)
True

For more information about the built-in basestring class, see Section 21.12, “isinstance(): Is a value an instance of some class or type?”.