Chapters
Python114 chapters

ReferenceBuilt-in functions

isinstance()

Checks whether an object is of a type, or of any type in a tuple.

Signature

isinstance(object, classinfo)

Parameters

NameMeans
objectthe value to test
classinfoa type, or a tuple of types

Returns

A bool. Unlike comparing type(), it accepts subclasses.

Example

Python
print(isinstance(5, int))
print(isinstance(5, (str, float)))
print(isinstance(True, int))

Output

True
False
True

See also