Skip to content
Built-in Functions

isinstance()

Check whether a value is an instance of a type.

isinstance(object, classinfo)

isinstance() returns True if the object is an instance of classinfo or a subclass thereof.

Supports checking against a tuple or union (int | str in Python 3.10+) of multiple types.

Parameters

NameDescription
objectThe value to test.
classinfoA type, class, or tuple of types and classes.

Returns

True if the object matches the given type or class; otherwise False.

Try it

Run it and change it
value = 3
print(isinstance(value, int))

Worth knowing

  • isinstance vs type(): Always prefer isinstance(obj, Class) over type(obj) == Class because isinstance correctly supports class inheritance and subclasses.

Related entries