class 继承
1. Person.py
class Person: def __init__(self,name,age): self.name = name self.age = age def __del__(self): print("person is reclaimed.") def wakeup(self,at): print("{0} wake up at {1} am".format(self.name,at)) mars = Person("xuefeifei", 30) print(mars.name) print(mars.age) mars.wakeup(7)
2. Employee.py
from Person import Person class Employee(Person): __counter = 0 #私有属性 def __init__(self,name,age,work_id): Person.__init__(self,name,age) self.work_id = work_id Employee.__counter += 1
3. Main.py
from Employee import Employee mars = Employee("xuefeifei",30,1109) print(Employee._Employee__counter) #私有属性的调用