Section 1: Advance Object-Oriented Programming
25% of the examWhat this topic covers
Create classes and use attributes, methods, inheritance, and polymorphism to model objects. Apply special methods such as __len__ and checks like isinstance and issubclass to support Python operations.
Does isinstance() return True for objects of a subclass too?
Yes, isinstance(obj, Shape) returns True when obj's class is Shape or any class that derives from it, at any depth. A check like type(obj) == Shape returns False for a Circle object, so isinstance() is the better choice when a superclass is involved.