题解 | #修改属性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("{}'salary is {}, and his age is {}".format(self.name,self.salary,self.age))
# 接收输入
name=input()
salary=int(input())
age=int(input())
# 为Employee类创建一个实例e
e=Employee(name,salary)
# 检验实例e有没有属性age
print(hasattr(e,"age"))
# 给实例e添加属性age
setattr(e,"age",age)
e.printclass()
OPPO公司福利 1202人发布