Class Employee with class attribute count. : Attribute : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Attribute »

 

Class Employee with class attribute count.


class Employee:
   count = 0       
   
   def __init__self, first, last ):
      self.firstName = first
      self.lastName = last

      Employee.count += 1

      print "Employee constructor for %s, %s" self.lastName, self.firstName )

   def __del__self ):
      Employee.count -= 1

      print "Employee destructor for %s, %s" self.lastName, self.firstName )


print "Number of employees before instantiation is", Employee.count

create two Employee objects
employee1 = Employee"A""C" )
employee2 = Employee"B""D" )
employee3 = employee1

print "Number of employees after instantiation is", employee1.count

# explicitly delete employee objects by removing references
del employee1
del employee2
del employee3

print "Number of employees after deletion is", Employee.count



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Attribute