class Employee:#类 模板
raise_count = 1.04 #类变量 每个实例共享的变量
num_of_emps = 0
def __init__(self, first, last, pay):#self 就是当前构建实例的自己 1实例变量 2构造方法 3自动调用 4 self当前实例 5 初始化要用的参数 用于后面的方法
self.first = first
self.last = last
self.email = first + '.' +last + '@c.com'
self.pay = pay
Employee.num_of_emps += 1
def fullname(self): #当前实例方法
return '{}{}'.format(self.first,self.last)
def apply_raise(self):
self.pay =int(float(self.pay) * self.raise_count)
class Developer(Employee):#继承类 子类 重写属性 重写方法
raise_count = 1.5
def __init__(self,first,last,pay,pro_lang):
super().__init__(first,last,pay)#super 就是调以前的父类 重用父类的init
print("hello")
self.pro_lang = pro_lang
class Manager(Employee):
def __init__(self,first,last,pay,employees= None):
super().__init__(first,last,pay)
if employees is None:
employees = []
else:
self.employess =employees
def add_emp(self,emp):
if emp not in self.employess:
self.employess.append(emp)
def remove_emp(self,emp):
if emp in self.employess:
self.employess.remove(emp)
def print_emp(self):
for emp in self.employess:
print(emp.fullname())
dev1 = Developer('John','ss','20000','python')
dev2 = Employee('Bohn','ss','50000')
# print(dev1.first,dev1.last,dev1.email,dev1.pay,dev1.pro_lang)
# # print(help(Developer))
# # dev1.apply_raise()
# # print(dev1.pay)
# # dev2.apply_raise()
# # print(dev2.pay)
# mgr_1 = Manager('s','z',9000,[dev1])
# print(mgr_1.first,mgr_1.last,mgr_1.pay,mgr_1.email)
#
# mgr_1.print_emp()
# mgr_1.add_emp(dev2)
# mgr_1.print_emp()
# mgr_1.remove_emp(dev1)
# mgr_1.print_emp()
#
# print(isinstance(mgr_1,Employee))# 什么是什么的实例 判断
# print(issubclass(Manager, Employee))#继承
# print(issubclass(Manager, Developer))#继承
# print()