This is the code so far:
class Player:
hand = []
def take(self, card):
hand.append(card)
And this is the error when I call that function:
hand.append(card)
NameError: global name 'hand' is not defined
I have tried making it global like so:
class Player:
hand = []
def take(self, card):
global hand
hand.append(card)
it didn’t help.
Try referencing the variable ‘hand’ through the ‘self’ pointer:
In Python, in a member function the self pointer always contains the value of the instance of the class that the function was called on, allowing you to edit the members of that instance.