I'm currently learning Python in OOP, I have a question about using list as a class attribute. The question is when I change something in objects it will also change that class attribute.
class Backet:
number_of_stone = 0
stone_collection = []
def __init__(self,name):
self.name = name
self.number_of_stone +=1
self.stone_collection.append(self.name)
stone_one = Backet('One')
stone_two = Backet('Two')
When I print out the stone_one
and stone_two.number_of_two
they are = 1 (I know this is correct). But when I print stone_one
and stone_two.stone_collection
they both give a list ["One","Two"]
.
My question is that should it be stone_one.stone_collection = ['One']
and stone_two.stone_collection = ['Two']