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

相关推荐
Jonathan Star23 分钟前
Ant Design (antd) Form 组件中必填项的星号(*)从标签左侧移到右侧
人工智能·python·tensorflow
普通网友39 分钟前
多协议网络库设计
开发语言·c++·算法
努力努力再努力wz40 分钟前
【Linux网络系列】:TCP 的秩序与策略:揭秘传输层如何从不可靠的网络中构建绝对可靠的通信信道
java·linux·开发语言·数据结构·c++·python·算法
deep_drink44 分钟前
【论文精读(三)】PointMLP:大道至简,无需卷积与注意力的纯MLP点云网络 (ICLR 2022)
人工智能·pytorch·python·深度学习·3d·point cloud
daxi1501 小时前
C语言从入门到进阶——第9讲:函数递归
c语言·开发语言·c++·算法·蓝桥杯
njsgcs2 小时前
langchain+vlm示例
windows·python·langchain
勇气要爆发2 小时前
LangGraph 实战:10分钟打造带“人工审批”的智能体流水线 (Python + LangChain)
开发语言·python·langchain
yy.y--2 小时前
Java数组逆序读写文件实战
java·开发语言
jz_ddk2 小时前
[实战] 从冲击响应函数计算 FIR 系数
python·fpga开发·信号处理·fir·根升余弦·信号成形
我命由我123452 小时前
Photoshop - Photoshop 工具栏(67)修补工具
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop