isinstance()

isinstance()

class A:
	pass

class B(A):
	pass

class C(B):
	pass

c = C()
print(isinstance(c, A))

Output: Evaluates to True

The 'isinstance()' function checks if the object (first argument) is an instance or subclass of the class (second argument). Although object c is derived from class C but class C inherits from B which in turn inherits from A, hence c will be considered an instance of A. Consider it like your family tree. You will be considered related to your Great Grand Parents even though you are not directly their child.

Last updated