Software & Finance

Python - Difference Between __init__ and __call__


I have given here python program that explains difference between __init__ and __call__. __init__ would be treated as Constructor where as __call__ methods can be called with objects any number of times. Both __init__ and __call__ functions do take default arguments.

This code is tested with Python version 2.6


        class CEmployee:
           age = 0
           name = ""
           def __init__ (self, name="unassigned", age=-1):
       = name
              self.age    = age
           def __call__ (self, name, age=10):
       = name
              self.age    = age
           def PrintRecord(self):
              print, self.age
        s1 = CEmployee()
        s1("Kathir", 33)

        #unassigned -1
        #kathir 10
        #kathir 33