python 中 __dict__函数的使用

class F:
def __init__(self, name, age):
self.name = name
self.age = age

obj = F('tom', 20)
s = obj.__dict__
print(s) # {'name': 'tom', 'age': 20}

__dict__获取类中的属性,并以键值对的形式存储

猜你喜欢

转载自www.cnblogs.com/jinbaobao/p/12056410.html