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

相关推荐
yz1.15 分钟前
[sklearn] 特征工程
python·机器学习·sklearn
老歌老听老掉牙15 分钟前
Open CASCADE学习|实现裁剪操作
c++·学习·opencascade·裁剪
hello_ejb32 小时前
聊聊Spring AI Alibaba的SentenceSplitter
人工智能·python·spring
新辞旧梦3 小时前
企业微信自建消息推送应用
服务器·python·企业微信
TPBoreas3 小时前
Jenkins 改完端口号启动不起来了
java·开发语言
虎头金猫3 小时前
如何解决 403 错误:请求被拒绝,无法连接到服务器
运维·服务器·python·ubuntu·chatgpt·centos·bug
TE-茶叶蛋3 小时前
Vuerouter 的底层实现原理
开发语言·javascript·ecmascript
云闲不收4 小时前
设计模式原则
开发语言
秋名RG4 小时前
深入解析建造者模式(Builder Pattern)——以Java实现复杂对象构建的艺术
java·开发语言·建造者模式
技术求索者5 小时前
c++学习
开发语言·c++·学习