Jan-27-2018, 12:54 AM
There is a easier solution than starting clone/copy stuff @ka06059.
Class attribute are owned by the class itself,so the attribute has the same value for each instance(object) of a particular class.
What i show are
Instance attributes are owned by the specific instance(object) of the class,so can vary from instance to instance of a specific class.
class Car: def __init__(self, color): self.color = color self.condition = ["0","0"] def drive(self): self.condition[0] = "1"Test.
>>> chevy = Car("Blue") >>> ford = Car("Red") >>> >>> # So now setting condition will only affect one object >>> chevy.drive() >>> chevy.condition ['1', '0'] >>> ford.condition ['0', '0'] >>>Orgianl post with
class attribute
:Class attribute are owned by the class itself,so the attribute has the same value for each instance(object) of a particular class.
What i show are
instance attribute
:Instance attributes are owned by the specific instance(object) of the class,so can vary from instance to instance of a specific class.