class Employee: empCount = 0 def __init__(self, name, salary,age): self.name = name self.salary = salary self.age=age Employee.empCount += 1 def displayCount(self): print "Total Employee %d" % Employee.empCount def displayEmployee(self): print "Name : ", self.name, ", Salary: ", self.salary, ", Age:", self.age "This would create first object of Employee class" emp1 = Employee("Zara", 2000,18) "This would create second object of Employee class" emp2 = Employee("Manni", 5000,19) emp1.displayEmployee() emp2.displayEmployee() print "Total Employee %d" % Employee.empCount print hasattr(emp1, 'age') # Returns true if 'age' attribute exists print getattr(emp1, 'age') # Returns value of 'age' attribute #print setattr(emp1, 'age', 8) # Set attribute 'age' at 8 #print delattr(empl, 'age') # Delete attribute 'age' print "Employee.__doc__:", Employee.__doc__ print "Employee.__name__:", Employee.__name__ print "Employee.__module__:", Employee.__module__ print "Employee.__bases__:", Employee.__bases__ print "Employee.__dict__:", Employee.__dict__
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question