Exemple #1
0
 def giveraise(self, percent, bouns=0.1):  #定制类
     # self.pay = self.pay * (1.0 + percent + bouns)
     Person.giveraise(self, percent + bouns)  #推荐使用这种方法,可以完美继承
Exemple #2
0
from class_person import Person

# zline = Person('Lin Zhang',30,15000,'network')
#
# print(zline.name,zline.pay)  #验证导入的类


class Manager(Person):  #继承类
    def __init__(self, name, age, pay):
        Person.__init__(self, name, age, pay, 'manager')

    def giveraise(self, percent, bouns=0.1):  #定制类
        # self.pay = self.pay * (1.0 + percent + bouns)
        Person.giveraise(self, percent + bouns)  #推荐使用这种方法,可以完美继承
        # self.giveraise(percent + bouns) #写法与上面一样
        # self.pay *= (1.0 + percent + bouns)


if __name__ == '__main__':
    tom = Manager(name='Tom Doe', age=50, pay=50000)  #基于映射关系传入数据
    bob = Person('Bob Smith', 42, 30000, 'networker')  #基于位置传入数据
    print(tom.getlastname())
    print(bob.getlastname())
    tom.giveraise(0.1)
    print(tom.pay)
    bob.giveraise(0.1)
    print(bob.pay)

    # tom.giveraise(.20)
    # print(tom.pay)