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

相关推荐
FreeCode9 分钟前
一文了解LangGraph智能体设计开发过程:Thinking in LangGraph
python·langchain·agent
西柚小萌新21 分钟前
【深入浅出PyTorch】--9.使用ONNX进行部署并推理
人工智能·pytorch·python
nvd1123 分钟前
SSE 流式输出与 Markdown 渲染实现详解
javascript·python
LDG_AGI23 分钟前
【推荐系统】深度学习训练框架(十):PyTorch Dataset—PyTorch数据基石
人工智能·pytorch·分布式·python·深度学习·机器学习
未来之窗软件服务28 分钟前
操作系统应用(三十三)php版本选择系统—东方仙盟筑基期
开发语言·php·仙盟创梦ide·东方仙盟·服务器推荐
zkl_zkl_31 分钟前
地理信息系统学习笔记——第六章 空间数据采集与处理
笔记·学习·数据处理·数据质量·空间数据
是Dream呀33 分钟前
昇腾实战|算子模板库Catlass与CANN生态适配
开发语言·人工智能·python·华为
光头程序员34 分钟前
学习笔记——主攻 vite
笔记·学习
零匠学堂202536 分钟前
移动学习系统,如何提升企业培训效果?
java·开发语言·spring boot·学习·音视频
小杨快跑~43 分钟前
从装饰者到桥接再到工厂:模式组合的艺术
java·开发语言·设计模式