最近看一些pytorch一些大佬写的代码太规范,一个类中套一个类,只会简单语法的小白表示一头雾水,自己编了一个小代码验证一下,不喜勿扰。
code
class grandfather():
def __init__(self,name,age):
self.name = name
self.age = age
self.height = 180
def plan(self):
print("爷爷的计划是环游世界")
def hobby(self):
print("爷爷最喜欢浪遏飞舟")
class father(grandfather):
def __init__(self,name,age):
super().__init__(name,age)
self.name = name
self.age = age
def diet(self):
print("父亲最喜欢小鸡炖蘑菇")
def hobby(self):
print("父亲最喜欢大美女")
def amazing(self):
super().plan()
class son(father):
def __init__(self,name,age):
super().__init__(name,age)
self.name = name
self.age = age
def game(self):
print("儿子最喜欢和平精英")
zhen1 = son("xiao_min",20)
print(zhen1.name)
zhen1.game()
zhen1.hobby()
zhen1.diet()
zhen1.amazing()
print(zhen1.height)
zhen1.plan()
zhen2 = father("da_ming",40)
zhen2.hobby()
zhen2.plan()
print(zhen2.height)
zhen3 = grandfather("lao_ming",90)
|