所以我刚刚开始学习python中的面向对象编程。我一直在学习一个教程,当我试图在一个类中打印位置参数时,总是会遇到一个错误。
class Employee:
raise_amount = 1.04
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + '.' + last + '@liv.ac.uk'
def fullname(self):
return '{} {}'.format(self.first, self.last)
def apply_raise(self):
return int(self.pay * Employee.raise_amount)
emp_1 = Employee('Lewis', 'Fisher', 50000)
emp_2 = Employee('Joe', 'Bloggs', 40000)
print(emp_1.apply_raise())
print(emp_2.pay())
代码在“print(Employee.pay())”处崩溃,错误如下。
TypeError: 'int' object is not callable
抱歉,这可能很简单,但我不能让它工作。
多谢提前通知,
刘易斯