8-21分享
1.读代码写结果 不允许运行
class A: discount = 0 def __init__(self): self.discount = 0.5 print('1', discount) class A: discount = 0.7 def __init__(self, price): self.discount = 0.2 self.price = price def show_price(self): return self.price * self.discount discount = 0.5 print('2', A.discount) print('3', A(10).discount) print('4', A(10).show_price())
2.看代码写结果
class B(object): def func(self): print("in B") class A(B):pass A().func()
class B(object): def func(self): print("in B") class A(B): def func(self): print("in A") A().func()
class B(object): def __init__(self): self.func() def func(self): print("in B") class A(B): def func(self): print("in A") A().func()