题解 | #修改属性2#
修改属性2
https://www.nowcoder.com/practice/7831806be5684ad6ac0f8b43e3e3558e
class Employee: def __init__(self,name,salary): self.__name = name self.__salary = salary def printclass(self): print(f"{self.__name}'salary is {self.__salary}, and his age is {self.age}") name = input() salary = int(input()) age = int(input()) e = Employee(name, salary) print(hasattr(e, 'age')) setattr(e,'age',age) e.printclass()