题解 | #修改属性1#
修改属性1
https://www.nowcoder.com/practice/c5ab441e5e8f4ec7bf36ba51a3141340
class Employee:
def __init__(self,name,salary):
self.name = name
self.salary = salary
def printclass(self):
print("{}'salary is {}, and his age is {}".format(self.name,self.salary,self.age))
def __setattr__(self, key, value):
self.__dict__[key] = value
# def __getattr__(self, item):
# return 1000
e = Employee(input(),input())
try:
e.printclass()
except:
print('Error! No age')
e.age = input()
def __init__(self,name,salary):
self.name = name
self.salary = salary
def printclass(self):
print("{}'salary is {}, and his age is {}".format(self.name,self.salary,self.age))
def __setattr__(self, key, value):
self.__dict__[key] = value
# def __getattr__(self, item):
# return 1000
e = Employee(input(),input())
try:
e.printclass()
except:
print('Error! No age')
e.age = input()
e.printclass()
#此题可以厂商使用python魔术方法、反射