functions

 

2023-09-24

doc:: 内置函数


getattr()

获取对象的属性值

语法:getattr(object, attribute, default)

1
class Person:
2
def __init__(self, name:str):
3
self.name = name
4
def get(self):
5
print(f"Hello {self.name}")
6
7
person = Person("immwind")
8
9
print(getattr(person, "name"))
10
11
get = getattr(person, "get")
12
get()