class Employee:
def __init__(self,name,salary):
self.name = name
self.__salary = salary
self.id = count + 1000
def count(self):
global count
count+=1
@property
def _add_(self, other):
if isinstance(other,Employee):
return people1.__salary + people2.__salary
count = 1
people1 = Employee('小明',2000)
people2 = Employee('小红',3000)
a=people1+people2
print(a)
作业题里的功能实现不了,不会做。
错误显示是:
Traceback (most recent call last):
File "D:\pycharm\project\01.py", line 19, in <module>
a=people1+people2
~~~~~~~^~~~~~~~
TypeError: unsupported operand type(s) for +: 'Employee' and 'Employee'
Process finished with exit code 1
然后重载和id自增还不太会。