Python isinstance() function
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
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
# Python program explaining # the isinstance() function class Instance: val = 51 TestInstance = Instance() print(isinstance(TestInstance, Instance)) print(isinstance(TestInstance, (list, tuple)))
Output
True False True