isinstance()

isinstance(obj, cls) asks whether an object is an instance of a class or any subclass of it; issubclass does the same for two classes.

In more detail

Prefer isinstance to comparing type(obj) == cls, because it respects inheritance. Checking types this way is best kept to the edges of a program, where outside data comes in.

Related terms

Taught in

References

Certification courses