Python isinstance() Function
Definition and Usage
If the specified object has the specified type, the isinstance() function returns True, otherwise it returns False.
If the type parameter is a tuple, then if the object is one of the types in the tuple, this function will return True.
Syntax
isinstance(object, type)
Parameter Value
Parameter | Description |
---|---|
object | Required. Object. |
type | Type or class, or a tuple of type and/or class. |
More Examples
Instance
Check if "Hello" is one of the types described by the type parameter:
x = isinstance("Hello", (float, int, str, list, dict, tuple))
Instance
Check if y is an instance of myObj:
class myObj: name = "Bill" y = myObj() x = isinstance(y, myObj)
Related Pages
Reference Manual:issubclass() Function(Check if an object is a subclass of another object)