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 trialHenry Lin
11,636 Points_by_value function?
In _by_value function, Kenneth did
for die in self:
if die == value:
do something
return dice
Does die == value
work because he overrode __eq__
method in dice.py?
Also return dice would return the actual number of each die's face is because he overrode __reper__
right?
[MOD: added formatting -cf]
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsDoes die == value work because he overrode __eq__
method in dice.py? Correct!
Also return dice would return the actual number of each die's face is because he overrode __repr__
right? In the _by_value
method, "dice" is a list that will contain all of the die matching value
append to the list.
In re-scanning the videos, I did not see where __repr__
was overridden.
Post back if you have more questions!
Johannes Scribante
19,175 PointsJohannes Scribante
19,175 PointsJust to clarify,
Hand()
is a subclass oflist
and is not a subclass ofDie()
. InDie()
the__repr__
was overridden, but even thoughHand()
contains a list of manyDie()
instances the__repr__
was not overridden inHand()
.We can however equate
die == value
because the list ofDie()
inHand()
eachDie()
instance is part of theDie class
which has overridden the__eq__
magic method and therefore we can equatedie == value
?Please correct me if I am wrong, I would just like to make sure I understand correctly
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsYes, Johannes, you are correct.