Python学习35天
# 定义父类
class Computer:
CPU=None
Memory=None
disk=None
def __init__(self,CPU,Memory,disk):
self.disk = disk
self.Memory = Memory
self.CPU = CPU
def get_details(self):
return f"CPU:{self.CPU}\tdisk:{self.disk}\tMemory{self.Memory}"
class PC(Computer):
brand=None
def __init__(self,CPU,Memory,disk,brand):
# 调用父类的方法初始化,
super().__init__(CPU,Memory,disk)
self.brand=brand
def print_brand(self):
# 打印信息同时调用父类的方法
print(f"brand:{self.brand}\t{self.get_details()}")
class NotePad(Computer):
color=None
def __init__(self,CPU,Memory,disk,color):
super().__init__(CPU,Memory,disk)
self.color=color
def print_color(self):
print(f"brand:{self.color}\t{self.get_details()}")
pc=PC("inter","32GB","500","联想")
notepad=NotePad("core","16GB",500,"黑色")
# 输出信息
pc.print_brand()
notepad.print_color()
原文地址:https://blog.csdn.net/2301_76865484/article/details/144092825
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!