The isinstance() function in Python allows checking if an object is of the specified type. In other words, it will check if the 1st parameter is a subclass of the 2nd parameter.
If it matches it will return True, otherwise, it will return False.
Now we’re gonna teach you to use the isinstance() function in Python.
x = isinstance(1, int) print(x)
x = isinstance(1, float) print(x)
If an object is of the specified type, this function will return True, otherwise, it will return False.
The case the parameter is of type tuple, if the object is one of type tuple, it will return True.
object: an object(Required)
type: class, type or tuple
class NAME: name = "BEND" z = NAME() x = isinstance(z, NAME) print(x)
testlist = [1, 2, 3] print(isinstance(testlist, list))
We just taught you to use the isinstance() function in Python.
Thank you for referring!
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.