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

相关推荐
Faker66363aaa几秒前
Arive-Dantu叶片识别系统:基于cascade-mask-rcnn_regnetx-400MF_fpn_ms-3x_coco模型实现_1
python
想你依然心痛2 分钟前
AI赋能编程语言挑战赛:从Python到Rust,我用AI大模型重塑开发效率
人工智能·python·rust
协同生态4 分钟前
天锐绿盾新版注册机【仅用于个人学习,禁止其他用途】
学习
quikai19817 分钟前
python练习项目
python
缺点内向11 分钟前
如何在 C# 中重命名 Excel 工作表并设置标签颜色
开发语言·c#·excel
Cuby!12 分钟前
【AFDM与信号处理:论文阅读】仿射频分复用:扩展OFDM以实现场景灵活性和弹性
论文阅读·笔记·学习·信息与通信·信号处理
Можно14 分钟前
深入理解 JavaScript 函数:分类、特性与实战应用
开发语言·javascript
淼淼76319 分钟前
工厂方法模式
开发语言·c++·windows·qt·工厂方法模式
Hui Baby29 分钟前
全局事务入口感知子事务方法-TCC
java·开发语言·数据库
AAA阿giao30 分钟前
从零开始学 React:用搭积木的方式构建你的第一个网页!
前端·javascript·学习·react.js·前端框架·vite·jsx