题解 | #修改属性2#
修改属性2
https://www.nowcoder.com/practice/7831806be5684ad6ac0f8b43e3e3558e
class Employee:
def __init__(self,name,salary):
self.name = name
self.salary = salary
def printcalss(self):
try:
print(f"{self.name}'salary is {self.salary}, and his age is {self.age}")
except Exception as e:
print('No age')
name = input()
salary = int(input())
e = Employee(name,salary)
print(hasattr(e,'age'))
setattr(e,'age',int(input())) #setattr函数表示,如果没有这个元素,就创建指定这个元素
e.printcalss()

