# __mro__ 查找继承顺序
class A(object):
pass
class B(A):
pass
class C(object):
pass
class D(B, C):
pass
print(D.__mro__) # (<class '__main__.D'>, <class '__main__.B'>, <class '__main__.A'>, <class '__main__.C'>, <class 'object'>),先从B的继承查找A,再找C,所以我们常用继承类优先写在前面,提高一点执行速度
# __dict__ 找对象的属性
class Func(object):
dream = "police"
def __init__(self, name, age):
self.name = name
self.age = age
def test(self, x):
return x+1
# 找类对象里的属性
print(Func.__dict__) # {'__module__': '__main__', 'dream': 'police', '__init__': <function Func.__init__ at 0x000002791FDCB0D0>, 'test': <function Func.test at 0x000002791FDCBEE0>, '__dict__': <attribute '__dict__' of 'Func' objects>, '__weakref__': <attribute '__weakref__' of 'Func' objects>, '__doc__': None}
obj = Func("hc", 24)
# 找实例对象里的属性
print(obj.__dict__) # {'name': 'hc', 'age': 24}