class Employee:
def __init__(self, first,last, pay):
self.first=first
self.last= last
self.email=first+'.'+last+'@company.com'
def fullname(self):
return '{} {}'.format(self.first,self.last)
def apply_rate(self):
self.pay=int(self.pay * 1.04)
emp_1=Employee('Rehim','Hesimov',50000)
emp_2=Employee('Test','User',60000)
print(emp_1.pay)
emp_1.apply_rate()
print(emp_1.pay)
回溯(最近一次调用)。 文件 "C:\Users\rehim\Desktop\class.py",第12行,在'' print(emp_1.pay)AttributeError: 'Employee'对象没有属性'pay'。谁能帮我解决这个问题?
看起来你缺少了 self.pay = pay
从 __init__
.