Here you have an example of a class name Animal and some instance names (dog, cat, cow) ...
class names by convention are capitalized
# category is global to the class and is available to all
# instances of class Animal
category = "animal"
def __init__(self, animal, sound):
__init__() is the 'constructor' of the class instance
when you create an instance of Animal you have to supply
it with the name and the sound of the animal
'self' refers to the instance
if the instance is dog, then
name and sound will be that of the dog
'self' also makes name and sound available
to all the methods within the class
self.name = animal
self.sound = sound
the first argument of a class method is always self
this method needs to be called with self.speak() within
the class, or the instance_name.speak() outside the class
print( "The %s goes %s" % (self.name, self.sound) )
# create a few class instances
# remember to supply the name and the sound for each animal
dog = Animal("dog", "woof")
cat = Animal("cat", "meeouw")
cow = Animal("cow", "mooh")
# testing ...
# now you can call each animals function/method speak()
# by simply connecting instance_name and speak() with a '.'
# you can also access variables associated with the instance
# since cow is the instance
# self.sound becomes cow.sound
# category is a class variable common to all istances
"""my result -->
The cow goes mooh
The cat goes meeouw
The dog goes woof
According to advice from The_Kernel (thanks) category" is considered a class variable, self.name and self.sound are instance variables.