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

相关推荐
MartinYeung55 分钟前
[论文学习]LLM 情境学习资料的快速精确遗忘技术:基于 In-Context Learning 与量化 K-Means 的 ERASE 方法
学习·算法·kmeans
yongche_shi7 分钟前
ragas官方文档中文版(十六)
python·ai·智能体·ragas·使用工具
三块可乐两块冰11 分钟前
rag学习5
linux·前端·python
DXM052115 分钟前
第11期| 遥感图像分类模型:ResNet_DenseNet原理+实战训练
人工智能·python·深度学习·机器学习·分类·数据挖掘·ageo
SilentSamsara18 分钟前
模型部署实战:FastAPI + ONNX + Docker 的推理服务化
人工智能·pytorch·python·深度学习·机器学习·fastapi
踏着七彩祥云的小丑19 分钟前
Go学习第8天:接口 + 泛型 + 错误处理
开发语言·学习·golang·go
fanged20 分钟前
高通学习12--调试工具(TODO)
学习
AI小百科21 分钟前
成为FDE的系统学习路径(2026版)
人工智能·学习·ai应用
聆风吟º22 分钟前
Python基础数据类型(一):数字类型
开发语言·python·float·int·bool·数字类型
Tisfy23 分钟前
LeetCode 3838.带权单词映射:求和、取模、拼接(附python一行版)
python·算法·leetcode·字符串·题解·模拟·取模