'pay'属性不被识别

问题描述 投票:-1回答:1
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'。谁能帮我解决这个问题?

python class methods attributes sublimetext3
1个回答
0
投票

看起来你缺少了 self.pay = pay__init__.

© www.soinside.com 2019 - 2024. All rights reserved.