Python isinstance() function
The isinstance() function in Python returns a Boolean value ‘True’ if the given object is of the specified type, otherwise it returns False.
Syntax
1 2 3 |
isinstance(object, classinfo) |
Parameter
object: It is a required parameter which represents an object.
classinfo: This parameter represents a type or a class, or a tuple of types and/or classes
Return
This function returns a Boolean value ‘True’ if the given object is of the specified type, otherwise it returns False.
Example 1
1 2 3 4 5 6 7 8 9 |
# Python program explaining # the isinstance() function class Instance: val = 51 TestInstance = Instance() print(isinstance(TestInstance, Instance)) print(isinstance(TestInstance, (list, tuple))) |
Output
1 2 3 4 5 |
True False True |