Python Object-Oriented Python Dice Roller Yatzy Scoring


I don't understand how can we use self in self.by_value(1). I get self is confusing most of the times. can anyone please give a clear understanding of using 'self'? class YatzyHand(Hand): def __init(self,args,*kwargs): super().init_(size=5,die_class=D6,args,*kwargs) @property def ones(self): return self._by_value(1)

1 Answer

Steven Parker
Steven Parker
204,855 Points

The "self" reference is just a convenient way to refer to a specific class instance from within the class code. When writing the class, the actual name of the instance(s) is not known, and you wouldn't want to be dependent on a particular name anyway.