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

相关推荐
云天AI实战派7 分钟前
AI 智能体问题排查指南:ChatGPT、API 调用到 Agent 上线失灵的全流程修复手册
大数据·人工智能·python·chatgpt·aigc
晓梦林8 分钟前
MAZESEC-X1靶场学习笔记
笔记·学习
我的xiaodoujiao44 分钟前
API 接口自动化测试详细图文教程学习系列15--项目实战演练2
python·学习·测试工具·pytest
TImCheng06091 小时前
职场人AI学习周期评估:不同学习路径的时间成本
人工智能·学习
周末也要写八哥1 小时前
C4D/Cinema 4D 2026超详细下载与安装教程(附资源包)
学习·数学建模
xinzheng新政1 小时前
openclaw dashboard报错 internal server error
学习
Gary Studio1 小时前
安卓HAL C++基础-智能指针
开发语言·c++
啧不应该啊1 小时前
Day1 Python 与 C 的类型区别
c语言·开发语言
多思考少编码2 小时前
PAT甲级真题1001 - 1005题详细题解(C++)(个人题解)
c++·python·最短路·pat·算法竞赛
cen__y2 小时前
Linux07(信号01)
linux·运维·服务器·c语言·开发语言