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

相关推荐
牛奔1 小时前
Go 如何打印调试深层或嵌套的结构体
开发语言·后端·golang
geovindu1 小时前
go: Iterative Algorithms
开发语言·后端·算法·golang·迭代算法
学逆向的1 小时前
汇编——JCC指令
开发语言·汇编·网络安全
西安老张(AIGC&ComfyUI)1 小时前
第034章:ComfyUI&AIGC一阶段学习总结及下阶段学习安排
学习·aigc
mayaairi2 小时前
JS循环语句深度解析:嵌套for、while与do...while
开发语言·前端·javascript
郭老二3 小时前
【Python】基本语法:装饰器语法糖@
python
kite01213 小时前
Go语言Map深度解析与最佳实践
开发语言·后端·golang
_Jimmy_4 小时前
Agent常用检索器的详细介绍
python·langchain
小柯南敲键盘4 小时前
图片翻译API接入与自动化实现指南
运维·python·自动化
正经人_x4 小时前
学习日记43:FINO
学习