classParent(): def__init__(self,name,sex): self.name = name self.sex = sex deftalk(self): returnf'{self.name}are walking' defis_sex(self): if self.sex == 'boy': returnf'{self.name} is a boy' else: returnf'{self.name} is a gril'
classChildOne(Parent): defplay_football(self): returnf'{self.name} are playing football' classChildTwo(Parent): defplay_pingpong(self): returnf'{self.name} are playing pingpong'
c_one = ChildOne(name='小木',sex='boy') result = c_one.play_football() result = c_one.talk() print(result)
c_two = ChildTwo(name='小云',sex='girl') result = c_two.play_pingpong() print(result)
p = Parent(name='小木爸爸',sex='boy') result = p.talk() print(result) result = p.is_sex() print(result)