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

相关推荐
习习.y4 分钟前
关于python中的面向对象
开发语言·python
lingggggaaaa5 分钟前
免杀对抗——C2远控篇&PowerShell&有无文件落地&C#参数调用&绕AMSI&ETW&去混淆特征
c语言·开发语言·笔记·学习·安全·microsoft·c#
技术净胜5 分钟前
MATLAB 基因表达数据处理与可视化全流程案例
开发语言·matlab
友友马5 分钟前
『Qt』多元素控件
开发语言·qt
hmbbcsm13 分钟前
练习python题目小记(六)
开发语言·python
wow_DG22 分钟前
【Python✨】VS Code 秒开 Python 类型检查:一招 mypy + settings.json 让你的 Bug 原地现形!
python·json·bug
4***V20231 分钟前
Vue3响应式原理详解
开发语言·javascript·ecmascript
q***985233 分钟前
VS Code 中如何运行Java SpringBoot的项目
java·开发语言·spring boot
Aspect of twilight39 分钟前
LeetCode华为大模型岗刷题
python·leetcode·华为·力扣·算法题
共享家95271 小时前
QT-界面优化(中)
开发语言·qt