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

相关推荐
mightbxg9 小时前
【学习一下】余弦相似度+Sigmoid+交叉熵组合
深度学习·学习·机器学习
Vallelonga9 小时前
Rust 中的枚举
开发语言·rust
兰令水9 小时前
leecodecode【状态机DP】【2026.6.9打卡-java版本】
java·开发语言·算法
郝亚军9 小时前
win11安装python3.12.7和pycharm
ide·python·pycharm
资深流水灯工程师9 小时前
PyCharm 虚拟环境完整配置指南(PySide6 开发专用)
ide·python·pycharm
AC赳赳老秦9 小时前
用 OpenClaw 整理学习笔记:自动提取视频课程内容、生成文字笔记、分类归档
大数据·运维·数据库·人工智能·学习·deepseek·openclaw
宸津-代码粉碎机9 小时前
Spring AI企业级实战|Agent长期记忆持久化落地,彻底解决多轮对话上下文丢失问题
java·开发语言·人工智能·后端·python·spring
在放️9 小时前
Python 爬虫 · bs4 模块基础
开发语言·爬虫·python
belong_my_offer9 小时前
Python 数据采集完全指南 —— 从零开始掌握网络爬虫与文件读取
开发语言·爬虫·python
Adorable老犀牛9 小时前
Prometheus 常用告警规则 rules.yml
开发语言·prometheus·exporter·nodeexpoeter