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

相关推荐
AI视觉网奇1 分钟前
glb读取颜色
开发语言·python
min(a,b)8 分钟前
学习第10天:日志、测试、配置与容器化部署
学习
xqqxqxxq9 分钟前
AI Agent学习:用户记忆系统(李博杰《深入理解 AI Agent》3.1观后总结)
人工智能·学习
wangyue_msn_8615 分钟前
Agent知识学习笔记——01 Prompt/Function call/记忆/上下文
笔记·学习·prompt
呱呱巨基19 分钟前
CMake基础
linux·c++·笔记·学习
半兽先生24 分钟前
2026年RAG系统主流开源文档解析工具选型指南:PaddleOCR、MinerU、LiteParse、HunyuanOCR、Apache Tika 全面对比
人工智能·python·机器学习·ai·开源
min(a,b)24 分钟前
AI 每日学习 — RAG 效果评估体系设计与实现
学习
程序员-Benothing1 小时前
如何实现高并发系统订单30分钟自动关闭?
开发语言·c#·wpf
智闲电子设计1 小时前
STM32 定时器 PWM 实战:从呼吸灯到舵机控制
c语言·stm32·单片机·嵌入式硬件·学习
郝学胜-神的一滴2 小时前
Python 高级编程 026:内置数据结构之骈文纵论
开发语言·数据结构·python·程序人生·软件工程