هک‌ها و تشعشعات وجدان آزاد

نوشته‌های سیدمحمدمسعود صدرنژاد

ابزار کاربر

ابزار سایت


courseware:python_programming:resources:code:21

ارث‌بری و تابع help

class Employee:
 
    def __init__(self, first, last, pay):
        self.first = first
        self.last = last
        self.email = first + '.' + last + '@email.com'
        self.pay = pay
 
    def fullname(self):
        return '{} {}'.format(self.first, self.last)
 
class Manager(Employee):
 
    def __init__(self, first, last, pay, employees=None):
        super().__init__(first, last, pay)
        if employees is None:
            self.employees = []
        else:
            self.employees = employees
 
    def add_emp(self, emp):
        if emp not in self.employees:
            self.employees.append(emp)
 
    def print_emps(self):
        for emp in self.employees:
            print('-->', emp.fullname())
 
class Developer(Employee):
 
    def __init__(self, first, last, pay, prog_lang):
        super().__init__(first, last, pay)
        self.prog_lang = prog_lang
 
dev_1 = Developer('Masoud', 'Sadrnezhaad', 5000, 'Python')
dev_2 = Developer('Test', 'Employee', 6000, 'Java')
mgr_1 = Manager('Mostafa', 'Amiri', 1000, [dev_1])
mgr_1.add_emp(dev_2)
 
print(mgr_1.print_emps())
help(dev_1)
courseware/python_programming/resources/code/21.txt · آخرین ویرایش: 2020/09/15 15:46 (ویرایش خارجی)