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

相关推荐
揽星河..9 分钟前
【C语言】指针
c语言·开发语言
小小数媒成员26 分钟前
UGUI原理(一)
开发语言·游戏·unity·游戏引擎
赵谨言30 分钟前
多语种在线语言学习平台LinguaVerse的设计与实现毕业论文
学习
VIP_CQCRE41 分钟前
内容自动化越跑越乱?先补上状态、去重和失败恢复
python·ai·工作流·幂等设计·内容自动化
速易达网络1 小时前
Three.js 动画入门教学:从场景搭建到流畅动效
开发语言·javascript·ecmascript
東隅已逝,桑榆非晚1 小时前
算法3.双指针法-快乐数
c++·笔记·学习·算法
福大大架构师每日一题1 小时前
excelize v2.11.1发布:Go 1.26.0起步,16项安全修复与嵌入对象能力全面升级
开发语言·安全·golang
我喜欢就喜欢1 小时前
RAG 重排序 Rerank 实战:用 bge-reranker 把 Top-K 命中率拉回来
python·大模型·向量检索·rag·rerank
Sarvartha1 小时前
集合概述 & Collection 接口
开发语言