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

相关推荐
程序猿_极客21 分钟前
【2025最新】 Java入门到实战:包装类、字符串转换、equals/toString + 可变字符串,一篇搞定开发高频场景(含案例解析)
java·开发语言·java进阶·面试核心·java快速入门
不知更鸟23 分钟前
无法联系上下文
python·django
U***e6332 分钟前
Python测试
开发语言·python
sensen_kiss42 分钟前
INT301 Bio-computation 生物计算(神经网络)Pt.8 主成分分析(PCA)与无监督学习
神经网络·学习·线性代数·机器学习
四谎真好看44 分钟前
Java 黑马程序员学习笔记(进阶篇28)
java·笔记·学习·学习笔记
金色熊族1 小时前
win11安装matplotlib过程
python·matplotlib
yi碗汤园1 小时前
Visual Studio常用的快捷键
开发语言·ide·c#·编辑器·visual studio
LFly_ice1 小时前
学习React-23-React-router
前端·学习·react.js
Elias不吃糖1 小时前
NebulaChat:C++ 高并发聊天室服务端
开发语言·c++·redis·sql·项目文档