七、面向对象_11.__dict__

dict

类对象/实例对象.__dict__
        功能:收集类对象或实例对象的属性和方法以及对应的值,并返回dict
class A(object):
    a1 = 0
    a2 = 1
    def __init__(self):
        self.b1 = 6
        self.b2 = 'BB'

    def sum(self,n,m):
        print( n + m )
a = A()

print(A.__dict__)
print(a.__dict__)

{'__module__': '__main__', 'a1': 0, 'a2': 1, '__init__': <function A.__init__ at 0x00000042DA8BEC18>, 'sum': <function A.sum at 0x00000042DA8BECA8>, '__dict__': <attribute '__dict__' of 'A' objects>, '__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None}
{'b1': 6, 'b2': 'BB'}
上一篇:python中列表元素的去重复


下一篇:WPS逆向