89DEVs

Python isinstance() function

overview of isinstance() function

The isinstance() function checks if the first argument is an instance of the class specified in the second argument.

example for isinstance()

The isinstance() function can be used to determine if the object is an instance or subclass of the specified class. # example of isinstance() numbers = [1, 2, 3, 4, 5] result = isinstance(numbers, list) print(result) The list numbers is a list and therefore the isinstance() function returns True. True

syntax of isinstance()

The syntax of isinstance() is: isinstance(object, class)

arguments of isinstance()

The isinstance() function accepts two arguments and both are required: The first argument is the object to be checked and the second argument is the class.

return values of isinstance()

The isinstance() function returns either True or False, depending if the object is an instance or subclass of the second argument.

                
        

Summary


Click to jump to section