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

相关推荐
m0_61788142几秒前
CSS如何让最后一行项目左对齐_利用flex布局配合伪元素空项填充
jvm·数据库·python
LiAo_1996_Y1 分钟前
CSS如何实现根据滚动进度触发的过渡效果_配合JS修改类名触发transition
jvm·数据库·python
Adellle1 分钟前
Java 异步回调
java·开发语言·多线程
海寻山2 分钟前
Java常用API详解(二):集合类API(ArrayList/HashMap/HashSet)实战,一篇吃透
开发语言·python
XMYX-02 分钟前
19 - Go 并发限制:限流与控制并发数
开发语言·golang
qeen873 分钟前
【算法笔记】差分与经典例题解析
c语言·c++·笔记·学习·算法·差分
z4424753264 分钟前
CSS如何实现文本溢出显示省略号_掌握text-overflow使用方法
jvm·数据库·python
大能嘚吧嘚5 分钟前
python3.13.x 创建虚拟环境
python
m0_515098426 分钟前
如何处理.NET中的Oracle Number溢出_OracleDecimal与C# decimal数据类型对应
jvm·数据库·python
2401_887724506 分钟前
Less如何优化CSS文件大小_利用压缩配置去除冗余样式
jvm·数据库·python