I'm new to OOP and having difficulty to understand mutability of class characteristics in Python. For example:
class Table:
def __init__(self, n_players):
self.n_players = n_players
self.hand_count = 0
def update_hand_count(self):
self.hand_count = self.hand_count + 1
return
def alternative_approach(self):
hand_count = self.hand_count
hand_count += 1
Can I be expected for both of these approaches to work reliably? I see that some types are immutable. So if I defined self.hand_count
as int(0)
, would this impact the result?
Unfortunately my code example is too complex to copy here (and I'm not even sure what it driving my issue). All I know is that I am seeing scope type errors emerge where I am reassigning values in my object instance, but I don't understand OOP / class structures in Python well enough to get myself out of trouble.