0
class Employee:
def __init__(self, first, last, pay):
self.k=first
self.p=last
self.l=pay
self.email=first+'.'+last+'@gmail.com'
h= self.email
return (h)
def fullname(self):
return ('{} {}'.format(self.k,self.p))
emp_1=Employee('Aditya','Shrivastava', 500000)
print(emp_1.fullname())`
Excepton:为什么它表明__init__函数应该始终不返回?
Traceback (most recent call last):
File "A:/Python/Programs/main.py", line 54, in <module>
emp_1=Employee('corey','schafer',50000)
TypeError: __init__() should return None, not 'str'
因为'__init__'应该总是返回'None'。删除'return(h)'。 –
*为什么你的'__init__'方法返回'self.email'? –
Aditya Shrivastava不要忘记接受并投票答案,你觉得有用,接受是与答案左上角的复选框,并投票与箭头 –