class Gun(object):
def init(self, name, num):
self.name = name
self.num = num
__snum = num
def __str__(self):
return "枪:%s" % self.name
def biubiu(self):
if self.num > 0: # 子弹足够
self.num -= 1 # 子弹发射
print("开火!biubiu~")
else:
print("咔咔,没子弹了")
class Fire_soldier(Gun):
def init(self, name):
self.name = name
def __str__(self):
return "特种兵:%s" % self.name
def fire(self):
print("%s按下扳机" % self.name)
super(Fire_soldier, self).biubiu()
def relod(self):
super().num += super().__snum
gun = Gun("沙漠之鹰", 7)
soldier = Fire_soldier("战狼")
soldier.fire()
print(Fire_soldier.mro)class Gun(object):
def __init__(self, name, num):
self.name = name
self.num = num
__snum = num
def __str__(self):
return "枪:%s" % self.name
def biubiu(self):
if self.num > 0: # 子弹足够
self.num -= 1 # 子弹发射
print("开火!biubiu~")
else:
print("咔咔,没子弹了")
class Fire_soldier(Gun):
def init(self, name):
self.name = name
def __str__(self):
return "特种兵:%s" % self.name
def fire(self):
print("%s按下扳机" % self.name)
super(Fire_soldier, self).biubiu()
def relod(self):
super().num += super().__snum
gun = Gun("沙漠之鹰", 7)
soldier = Fire_soldier("战狼")
soldier.fire()