Built-in Functions and Types

isinstance()

Check an object against one or more runtime types, including inherited and supported virtual-subclass relationships. A tuple or union of valid classes can test alternatives. This is not an exact-type comparison: True is also an int instance. Parameterized generics such as list[int] are not general runtime validators; invalid class information can raise TypeError. Earlier successful tuple or union checks may avoid later invalid entries.

Formal Syntax & Structure

python syntaxpython
isinstance(object, classinfo, /)

Parameters & Attributes

NameTypeDescription
objectobjectValue being inspected.
classinfotype | tuple of types | union typeRuntime class information; nested tuples are accepted.

Return Value

bool

True if an applicable instance relationship matches.

Working Example

Example Snippetpython
print(isinstance(True, int))print(isinstance("42", (int, str)))print(isinstance(4.5, int | str))
Python Reference