Software & Finance

Python - Constructor __init__


I have given here python program explaining on how to write your first Python Class and a Constructor with __init__

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 PrintRecord(self):
              print, self.age
        s1 = CEmployee();
        s2 = CEmployee("Kathir", 33);

        #unassigned -1
        #kathir 33