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

相关推荐
justjinji1 分钟前
如何用组合继承模式实现父类方法复用与子类属性独立
jvm·数据库·python
We་ct2 分钟前
LeetCode 64. 最小路径和:动态规划入门实战
开发语言·前端·算法·leetcode·typescript·动态规划
CoderCodingNo3 分钟前
【CSP】CSP-J 2019 江西真题 | 次大值 luogu-P5682 (适合GESP四、五级及以上考生练习)
开发语言·c++·算法
djjdjdjdjjdj16 分钟前
PHP函数如何监控CPU温度传感器_PHP读取核心温度硬件值【详解】
jvm·数据库·python
Hui Baby18 分钟前
java抠图
java·开发语言
m0_6138562920 分钟前
c++怎么把多个变量一次性写入二进制文件_结构体对齐与write【实战】
jvm·数据库·python
Dxy123931021622 分钟前
Python设置Excel表格边框样式:从基础到高级
前端·python·excel
gihigo199823 分钟前
30节点系统最优潮流计算(MATLAB实现)
开发语言·matlab
꧁细听勿语情꧂43 分钟前
向下调整算法,top - k 问题,链式结构二叉树,前中后序遍历
c语言·开发语言·数据结构·算法
2301_780943841 小时前
第三阶段:Gem5-GPU集成学习
学习