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

相关推荐
南宫萧幕几秒前
基于最优控制理论的 HEV 能量管理:从物理建模到 VMD-PPO 强化学习环境构建
开发语言·人工智能·matlab·simulink·控制
froginwe112 分钟前
Memcached get 命令详解
开发语言
李日灐2 分钟前
<4>Linux 权限:从 Shell 核心原理 到 权限体系的底层逻辑 详解
linux·运维·服务器·开发语言·后端·面试·权限
renhongxia14 分钟前
计算机视觉实战:图像去噪模型训练与应用
开发语言·人工智能·机器学习·计算机视觉·prompt
寒秋花开曾相惜5 分钟前
(学习笔记)4.1 Y86-64指令集体系结构(4.1.6 一些Y86-64指令 )
linux·运维·服务器·开发语言·笔记·学习·安全
weixin_441003647 分钟前
357本Python精品书籍pdf电子书下载
python·pdf
心勤则明15 分钟前
基于Spring AI Alibaba的监督者模式实践
人工智能·python·spring
城管不管17 分钟前
EasyExcel
java·开发语言·后端·easyexcel
蓝桉~MLGT20 分钟前
Ai-Agent学习历程—— Harness和Memory介绍和应用 & vibe Coding工具选择
人工智能·学习
1368木林森21 分钟前
深入浅出:JDK1.7→JDK1.8 HashMap进化史,再到ConcurrentHashMap的并发救赎
java·开发语言