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

相关推荐
用户2986985301415 分钟前
Python 自动化处理 Word 页眉页脚的几种典型场景
后端·python·api
小小晓.25 分钟前
Qt 对话框、QLineEdit 与布局管理实战详解
开发语言·qt
終不似少年遊*28 分钟前
【安全业务Agent】从场景到编排
python·react.js·ai·langchain·agent·安全架构·工作流
AKA__Zas36 分钟前
接口自动化测试(1.0 初认识
python·ci/cd·学习方法
炸薯条!1 小时前
博客系统测试报告
开发语言·lua
Evand J1 小时前
【MATLAB例程12】永磁同步电机基于增广无迹卡尔曼滤波的未知负载转矩在线观测
开发语言·matlab
用户0332126663671 小时前
使用 Python 在 Excel 文档中添加水印
python·excel
lisw051 小时前
作为人类代理的大语言模型及其角色分类!
人工智能·学习·语言模型
高洁011 小时前
自然语言处理的技术演进与核心任务
人工智能·python·深度学习·机器学习·迁移学习
Z21-X1 小时前
云原生运维实战笔记:企业网站综合上云部署与云运维服务全景解析
运维·笔记·学习·云原生