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

相关推荐
QQ54164512115 分钟前
【驿帮查件助手python开源】开源聚合查件机器人,实现 24 类驿站批量查件取代短信通知。技术方案分享
python·机器人·开源·驿站查件机器人
卷无止境19 分钟前
当FastAPI项目开始"膨胀",代码该往哪儿放
后端·python
用户83562907805133 分钟前
Python设置PowerPoint幻灯片背景的方法
后端·python
wang_yb34 分钟前
Python 中 10 个最常用的统计函数
python·databook
databook39 分钟前
Python 中 10 个最常用的统计函数
python·数据分析
大白同学4211 小时前
初识Qt——创建第一个Qt项目
开发语言·qt
祈禾1 小时前
计算机组成原理之编译、汇编、链接、解释
开发语言·汇编·笔记·学习
吴声子夜歌1 小时前
正则指引——Ruby
开发语言·正则表达式·ruby
艾琳_lab1 小时前
Python环境配置:pip镜像设置
python
知识分享小能手1 小时前
线性代数学习教程,从入门到精通,矩阵的初等变换与线性方程组(6)
学习·线性代数·矩阵