面对对象的特征
封装,继承,多态—对同一消息,作出不同响应。
class Employee:
def init(self,department,name,birthdate,salary):
self. department = department
self. name = name
self. birthdate = birthdate
self. salary = salary
def give_raise(self,percent,bonus=.0):
self.salary=self.salary*(1+percent+bonus)
def repr(self):
return’<员工:{}>’ .format(self.name)
def working(self):
print(‘员工:{},在工作…‘ .format(self.name))
class Programer(Employee):
def init(self,department,name,birthdate,salary,speciality,project):
super().init(department,name,birthdate,salary)
self. speciality = speciality
self. project = project
def working(self):
print(‘程序员:{}在开发项目:{}…’ .format(self.name,self.project)
if name=‘main’:
p=Programer(‘技术部’,’Peter’,datetime.date(1990.3.2),8000,’Flask’,’CRM’)
p. give_raise(.2, .1)
print(p.salary)
p.working
Python8 面对对象的特征
最新推荐文章于 2024-10-07 21:17:34 发布