Python学习35天

[复制链接]
发表于 2025-12-19 15:08:03 | 显示全部楼层 |阅读模式
# 界说父类
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()





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表