class Wangjianlin:
def __init__(self): self._name="王健林" self.__post="万达董事长" self._money=10000000000
def buy(self,name,price): if price>1000000: print('太贵了!') return self._money-=price print("花费%s,购买了%s"%(price,name)) def say(self): print("我是%s,我有钱:%s,职务是:%s"%(self._name,self._money,self.__post))
class Wangsicong(Wangjianlin): pass
wangjianli=Wangjianlin() wangjianli.say() wangjianli.buy("给网红刷游艇",5000000)
wangjianli.buy("给网红刷歼20",500000) wangjianli.say()
""" 当子类没有__init__()方法时,调用了父类的__init__()方法
也继承了父类的属性(非私有) """ wsc=Wangsicong() """ 继承了父类的say() """ wsc.say()