Check whether a value belongs to a built-in type, a DSL value class, or a user-defined class. Does not convert the value.
Syntax
isinstance(value, class_or_tuple, /)Parameters
| Name | Description |
|---|---|
valueAny | Value to check. Required · Positional only No default |
class_or_tupleType | tuple[Type, ...] | Use unquoted type references: bool, int, float, str, list, tuple, dict, set, range, enumerate, zip; DSL value classes such as Point, Match or AudioMatch; or a user-defined class. Tuples may nest and are checked left to right until a match. An invalid entry reached before a match raises TypeError. Strings and type(value) are rejected because type() returns text. Flow, System, Storage, Touch, ScreenCapture and Recognition are namespaces or contexts, not types. Required · Positional only No default |
Returns
Boolean — True for a matching type; otherwise False, including an empty tuple. bool also matches int; int and float are distinct. User-defined classes match by their definition, even when names are identical.Example
# Check a value before using it
value = 42
if isinstance(value, (int, float)):
print(value + 1)
print(isinstance(Point(10, 20), Point))