热线电话:13121318867

登录
2019-03-24 阅读量: 586
getattr的用法

Getattr:getattr()方法返回对象的命名属性的值。

如果未找到,则返回提供给函数的默认值.getattr方法采用三个参数objectnamedefault(可选)。

example:
class Employee:
salary = 25000
company_name= "geeksforgeeks"

employee = Employee()
print('The salary is:', getattr(employee, "salary"))
print('The salary is:', employee.salary)
Output:
The salary is: 25000
The salary is: 25000

9.5575
0
关注作者
收藏
评论(0)

发表评论

暂无数据