Akshaan Mazumdar2,356 Points
Why do we call super in the Hand class >(class Hand (list):) when it does not actually extend from any other superclass?
The first class we make we see Hand actually act as a list .But why have we called
super().__init__ in it?
Chris FreemanTreehouse Moderator 59,027 Points
Good question! When sub-classing, or extending, another class, all of the methods of the parent class are automatically available, including the
If you create a method in the sub-class with the same name as a method in the parent class, the local sub-class version will override the parent version. The parent version will not be executed unless explicitly called. The
super() function is used to explicitly call the method from the parent class.
In this case,
super allows the
__init__ from the parent
list to also run to initiate.
In classes of multiple inheritance, each parent also typically includes a
super() call so the next parent in the chain can run it’s
__init__. If you want to subclass
Hand further, you want the
super call so it can also be used in multiple inheritance.
Post back if you need more help. Good luck!!!
Jay ReyesPython Web Development Techdegree Student 15,935 Points
Chris Freeman - When we
super().__init__ the parent class: are we only in the scope of that class's
__init__ method (therefore excluding methods outside of the
__init__ but still inside the class)? Or are we in the scope of the entire class - so we also "import" all the methods and attributes there?