Python Object-Oriented Python Dice Roller Giving a Hand

Andrew McLane
Andrew McLane
3,385 Points

need help with understanding super() use.

So I need help understanding a couple of things:

  1. I understand that a class without a specified parent class always has python's parent class of 'object'. However, why do we need to use super. Thought this was so taht we could borrow a paren'ts initialization method, but here we aren't even using arguments (in the first part of the video).

  2. I thought the parenthesis for a subclass was used to specify the name of a parent class, but here we use 'list'. I'm not sure I understand how we are allowed to do this, and how python differentiates between a class parent name and a type argument.

Thanks!

1 Answer

Ryan Cross
Ryan Cross
5,738 Points

1 One of the important things children get from super().init() are the parents methods. List has append , extend etc. Without super()init() you would either not have any of those or have to design/build them if you needed them.

2 List is a class. its true its a built in class like string or tuple but none the less it is a class. It has object as a parent and it can have children. Here we make a class based on list. list is a parent to Hand.

Jay Reyes
Jay Reyes
Python Web Development Techdegree Student 15,935 Points

Ryan, wouldn't extending the Hand from list:

class Hand(list):

Be enough for the list methods to be initialized?