Concept

Check if an Object is an instance of a specific Class

We can use the built-in isinstance() method to check if an object is an instance of a specific Class. The syntax for this method is isinstance(object, class). If the object is an instance of that class, the method will return True, if not, it will return False. Example-

class Employee: id = 7 emp1 = Employee() print(isinstance(emp1, Employee)) #Prints True print(isinstance(1, int)) #Prints True

0

1

Updated 2021-02-14

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science