所以我才刚刚开始学习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
对不起,这可能非常简单,但我无法正常工作。 先谢谢了, 刘易斯
答案 0 :(得分:0)
您已经在pay
方法中将__init__
定义为整数变量。如果您想查看它的价值,只需使用
print(emp_1.pay)
但是没有诸如调用整数之类的事情,因此您不能使用pay()
。