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 trialKafe Hezam
11,070 PointsI don't understand what does die_class() in the for loop do and why is it usefull?
I just don't understand what die_class() do and what function is it calling?
2 Answers
Steven Parker
231,248 PointsThe "die_class" was provided as an argument to the "Hand", and defines what kind of objects (die) will be rolled. The argument passed in will be the name of the class that defines those objects.
Each time "die_class()" is called, an object of that class is created so that it can be added to the "Hand". So, for example, if a hand is created by calling *hands.Hand(size=5, die_class=dice.D6)
" then you will get a set of 5 6-sided dice (which is typical for a Yahtzee game). Each call t "die_class()
" in that case will actually be creating a "D6" object.
Chul Kim
2,341 PointsJust wondering is die_class just a random name that holds the actual class?
And the () is always used to call a certain function or class?
Steven Parker
231,248 PointsI wouldn't say "random", as the name "die_class" follows the "best practice" of being descriptive of what the variable is used for. And yes, you are completely correct in that it holds the actual class.
You are also correct that parentheses are required when you call any function or method. If arguments are used, they will be placed inside the parentheses, but the parentheses must still be there even if there are no arguments.