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

相关推荐
聆风吟º19 分钟前
【金仓数据库征文】Java 应用接入金仓数据库:从驱动、连接池到存储过程调试的踩坑实录
java·开发语言·数据库
迪丽热爱20 分钟前
每日英语-7
学习
森G35 分钟前
comfyui安装ComfyUI-Manager失败问题-解决办法
python
过期的秋刀鱼!37 分钟前
倾斜数据集的错误指标-混淆矩阵
人工智能·python·深度学习·机器学习·概率论·模型评估
LccKyI38 分钟前
C#学习day04
经验分享·笔记·学习·c#
math_hongfan38 分钟前
鸿蒙企业级数据存储高级架构:从读写分离到冷热数据分层/归档策略/数据生命周期管理最佳实践
人工智能·学习·华为·架构·harmonyos·鸿蒙
MartinYeung542 分钟前
[论文学习]LLM智能体无法保密:多智能体系统中的隐私评估
人工智能·学习
、达西先生43 分钟前
GMR IK数学原理解读
笔记·学习·il·遥操作·模仿学习
令狐前生43 分钟前
DDD领域模型学习笔记
笔记·学习·架构
不会代码的小猴1 小时前
11. 类和动态内存分配
开发语言·c++