面向对象之继承与派生
例1:非菱形继承,经典类与新式类的属性查找顺序都一样
# class E:
# # def test(self):
# # print('from E')
# pass
#
# class F:
# def test(self):
# print('from F')
#
#
# class B(E):
# # def test(self):
# # print('from B')
# pass
#
# class C(F):
# def test(self):
# print('from C')
#
#
# class D:
# def test(self):
# print('from D')
#
#
# class A(B, C, D):
# # def test(self):
# # print('from A')
# pass
#
# obj=A()
# obj.test()
# class E:
# # def test(self):
# # print('from E')
# pass
#
# class F:
# def test(self):
# print('from F')
#
#
# class B(E):
# # def test(self):
# # print('from B')
# pass
#
# class C(F):
# def test(self):
# print('from C')
#
#
# class D:
# def test(self):
# print('from D')
#
#
# class A(B, C, D):
# # def test(self):
# # print('from A')
# pass
#
# obj=A()
# obj.test()
# 例2:菱形继承
class G(object): # 在python2中,未继承object的类及其子类,都是经典类
# def test(self):
# print('from G')
pass
class G(object): # 在python2中,未继承object的类及其子类,都是经典类
# def test(self):
# print('from G')
pass
class E(G):
# def test(self):
# print('from E')
pass
# def test(self):
# print('from E')
pass
class F(G):
# def test(self):
# print('from F')
pass
# def test(self):
# print('from F')
pass
class B(E):
# def test(self):
# print('from B')
pass
# def test(self):
# print('from B')
pass
class C(F):
# def test(self):
# print('from C')
pass
# def test(self):
# print('from C')
pass
class D(G):
# def test(self):
# print('from D')
pass
# def test(self):
# print('from D')
pass
class A(B,C,D):
# def test(self):
# print('from A')
pass
# def test(self):
# print('from A')
pass
# obj=A()
# obj.test()
# obj.test()
print(A.mro())
每天逼着自己写点东西,终有一天会为自己的变化感动的。这是一个潜移默化的过程,每天坚持编编故事,自己不知不觉就会拥有故事人物的特质的。 Explicit is better than implicit.(清楚优于含糊)