I am new to Python so this might be a very dull question, though I have searched a lot on the subject and could not find an answer.
So I am trying to code a simple "card game", and for that defined a class "Player", containing the list attribute "cards". I have made sure this attribute is within "def init" so that it is specific to the class instance, however when I append an element to this list for a Player A, it also appends it for Player B. Note: my code also includes a class "Deck" and "Card" that I do not explicitate here to keep it light)
class Player(object): #defines Player class, including its score and name
all_players=[]
def __init__(self,score,name,cards=[]):
self.score=score
self.name=name
self.cards=cards
Player.all_players.append(name)
playera=Player(0,'John')
playerb=Player(0,'Bill')
playera.cards.append(Deck.hidden_cards[0])
==> playera.show_cards() and playerb.show_cards() then print the same results
If someone could help me on that it would be much appreciated ! Thanks in advance.