Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Dice Roller Project Breakdown

value=value

In the D6 class, Kenneth uses the super() function to call the init in the Die class. I don't understand why he passed value=value. Wouldn't just value be enough? e.g. super().init(sides=6, value)

1 Answer

Mathieu HAYS
Mathieu HAYS
9,623 Points

What he's using is called keyword arguments. You can learn more about them below: https://docs.python.org/2/tutorial/controlflow.html#keyword-arguments

In the video he could have used this: super().init(6, value) but you can't use super().init(sides=6, value) because all positional arguments have to be first.

Hope that makes sense.

Mathieu HAYS
Mathieu HAYS
9,623 Points

I should also add that using keyword arguments also has the added benefit to eliminate any "magic" value. What I mean by "magic" value is that if you look at your code in a few months or years, you might not know what that 6 was for. Or at least it makes it an easier read, so you don't have to check each of your methods/functions declarations to understand what's going on.