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

相关推荐
你想知道什么?3 小时前
线性回归-学习笔记
笔记·学习·线性回归
鱼毓屿御3 小时前
从「只会聊」到「边想边做」的跃迁
前端·学习·react.js
dreamer_83993 小时前
AI智能合同比对系统:从零搭建实战教程
人工智能·python
噢,我明白了4 小时前
java中Excel的导入和导出(EasyExcel)
java·开发语言·excel
AOwhisky4 小时前
Python 学习笔记(第十五期)——运维自动化(下·后篇):堡垒机实战——paramiko高阶篇
运维·python·学习·云原生·自动化·运维开发
mabing9934 小时前
Qt 生成条纹图
开发语言·qt
观察员4 小时前
带你用一个 Python 图书系统,通关封装继承多态
python
蓝悦无人机4 小时前
C++基础 — 函数总结
开发语言·c++
糖果店的幽灵5 小时前
langgraph的 MessagesState 解读
java·开发语言·人工智能·windows·langgraph
Fu_Lin_5 小时前
Qt 嵌入式从零基础到精通总纲
开发语言·qt·嵌入式·qt嵌入式