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

相关推荐
好家伙VCC2 分钟前
Rust+Bioinfo:80ms极速SNP注释引擎
java·开发语言·算法·rust
啦哈拉哈3 分钟前
【Python】知识点零碎学习7
python·学习·算法
宝贝儿好6 分钟前
【NLP】第八章:项目实操案例:文本情感分析
人工智能·python·深度学习·算法·自然语言处理
qq4356947016 分钟前
Vue02
开发语言·前端·javascript
代码中介商7 分钟前
C++11右值引用与移动语义深度解析
开发语言·c++
码上有光8 分钟前
c++:二叉搜索树(map和set的底层结构)
开发语言·c++·递归·二叉搜索树
Fuly10249 分钟前
LangGraph学习-(1)跑通一个最小状态图
数据库·学习
段一凡-华北理工大学9 分钟前
工业领域的Hadoop架构学习~系列文章19:能源行业Hadoop应用实践
大数据·人工智能·hadoop·分布式·学习·架构·高炉炼铁
syagain_zsx10 分钟前
Linux进程控制学习总结(1/2)
linux·运维·学习
AsiaLYF13 分钟前
Kotlin MutableSharedFlow: emit vs tryEmit 详解
开发语言·前端·kotlin