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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2021-10-12
  • 2021-11-29
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2021-06-27
  • 2022-01-19
  • 2022-01-24
  • 2021-10-05
  • 2022-02-01
相关资源
相似解决方案