December 2018
Beginner to intermediate
796 pages
19h 54m
English
We've already seen class declarations, such as class ClassA: pass and class ClassB(BaseClassName): pass. When we don't specify a base class explicitly, Python will set the special object class as the base class for the one we're defining. Ultimately, all classes derive from an object. Note that, if you don't specify a base class, brackets are optional.
Therefore, writing class A: pass or class A(): pass or class A(object): pass is exactly the same thing. The object class is a special class in that it has the methods that are common to all Python classes, and it doesn't allow you to set any attributes on it.
Let's see how we can access a base class from within a class:
# oop/super.duplication.pyclass Book: def __init__(self, ...Read now
Unlock full access