Python Object-Oriented Python Dice Roller Project Breakdown

Nicholas Abate
Nicholas Abate
1,643 Points

Super() Arguments

I know this was a topic covered earlier, but being able to practice highlighted some lack of understanding.

What is the difference between the arguments placed in the init() method vs the super().init() method?

And what is the purpose in assigning value = 0 in the init() method, and then setting value = value within the super().init() method? Isn't that redundant?

class D6(Die):
    def __init__(self, value = 0):
        super().__init__(sides = 6, value = value)

1 Answer

Steven Parker
Steven Parker
201,913 Points

The names on the "def" line are parameters (incoming) of the current class Those in the call to the "super" method are arguments being passed to the parent method.

The "value = 0" in the "def" line defines an optional positional parameter. If one is not passed in, it will get the value of 0. But the "value = value" in the call passes a keyword argument (kwarg) to the parent method.