Situatie
The isinstance() function checks if the object (first argument) is an instance or subclass of classinfo class (second argument).
isinstance() returns:
- True if the object is an instance or subclass of a class or any element of the tuple
- False otherwise
If classinfo is not a type or tuple of types, a TypeError exception is raised.
Solutie
Pasi de urmat
class Foo:
a = 5
fooInstance = Foo()
print(isinstance(fooInstance, Foo))
print(isinstance(fooInstance, (list, tuple)))
print(isinstance(fooInstance, (list, tuple, Foo)))
Output:
True
False
True
Leave A Comment?