Python Function Reference

isinstance

Check whether an object belongs to the given type or its subclass.

Python 3.13
isinstance(object, classinfo)
object
The object to check.
Any
classinfo
A class, a tuple of classes or a union such as int | float: any of them matches.
type | tuple | UnionType

Return value

True or False.

Examples

Checking the type of a number

Python 3.13
print(isinstance(5, int))
True

Checking against several types

Python 3.13
print(isinstance(3.5, (int, float)))
True

bool is a subclass of int

Python 3.13
print(isinstance(True, int))
True

Details

Unlike type(x) == int, isinstance takes inheritance into account. bool is a subclass of int, so isinstance(True, int) gives True.

See also

Where to learn