Each object has its own set of functions and variables, and you can manipulate those variables independently of objects of the same type. In addition, some class variables are set to a default value for all classes and can be manipulated globally.
This script demonstrates two objects of the
dog class being created, each with its own name:
class Dog(object): name = "Lassie" def bark(self): print self.name + " says 'Woof!'" def set_name(self, name): self.name = namefluffy = Dog()fluffy.bark()poppy = Dog()poppy.set_name("Poppy")poppy.bark()
That outputs the following:
Lassie says 'Woof!'Poppy says 'Woof!'
There, each dog starts with the name
Lassie, but it gets customized. Keep in mind that ...