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__获取类中的属性,并以键值对的形式存储
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__获取类中的属性,并以键值对的形式存储