1、类的__dict__属性和类对象的__dict__属性
结论:
a、类的静态函数、类函数、普通函数、全局变量以及一些内置的属性都是放在类__dict__里的
b、对象的__dict__中存储了一些self.xxx的一些东西
class TestName:
a = 2
b = 2
def __init__(self,c):
self.a = 0
self.b = 1
self.c = c
def test1(self):
print("a normal func")
@staticmethod
def static_test(self):
print("a static class")
@classmethod
def class_test(self):
print("a class func")
o = TestName(2)
print(TestName.__dict__)
print(o.__dict__)
结果:
{'__module__': '__main__', 'a': 2, 'b': 2, '__init__': <function TestName.__init__ at 0x000001EFA81DD268>, 'test1': <function TestName.test1 at 0x000001EFA81DD1E0>, 'static_test': <staticmethod object at 0x000001EFA801B390>, 'class_test': <classmethod object at 0x000001EFA801B320>, '__dict__': <attribute '__dict__' of 'TestName' objects>, '__weakref__': <attribute '__weakref__' of 'TestName' objects>, '__doc__': None}
{'a': 0, 'b': 1, 'c': 2}