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()

相关推荐
辣知2 分钟前
辣知·化智19 人类文明的轮回
学习
yk 坤帝3 分钟前
用Python实现发送《自动周报》实战脚本
开发语言·python
一点一木1 小时前
Seed Evolving 深度测评:我用它造了一个 AI 出题工具
人工智能·python·github
xian_wwq2 小时前
【学习笔记】RAG 只是 Context Engineering 的一小块-5/16
笔记·学习·rag
abbgogo2 小时前
OSPF动态路由协议
开发语言·php
123_不打狼2 小时前
零基础到就业:完整计算机视觉系统化学习路线指南
人工智能·学习·计算机视觉
en.en..2 小时前
C 语言嵌入式事件驱动状态机完整教程(枚举配套)
c语言·开发语言
阿童木写作2 小时前
跨境卖家效率翻倍,跨马翻译批量图片翻译工具实测
人工智能·python
鹿鹿学长2 小时前
2026国赛报名季:从组委会第一次通知到各校8月报名通知,赛程报名评奖官方口径一次讲清
python·自动化
Tim_102 小时前
【C++】024、new[]与delete[]配对使用
java·开发语言