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

相关推荐
可乐鸡翅yeah_5 分钟前
hls.js 切换多个视频源,新手开发常见踩坑
开发语言·前端·javascript·ios·ffmpeg·音视频·safari
Tanshu_API君8 分钟前
API 聚合平台选型指南:从参数拆解到生产落地的十个评估维度
开发语言·api
Chen—LSN9 分钟前
C语言——⽂件操作(1)
c语言·开发语言·c++·经验分享·笔记·算法·链表
传奇开心果编程10 分钟前
【Flutter入门练中学】第8课:动画与过渡
android·学习·flutter·ui·ios
狗凯之家源码网12 分钟前
PHP 开源 IM 即时通讯系统效果实测与功能展示
开发语言·开源·php
虎虎(_ _)。゜zzZ26 分钟前
关于字典中的解包问题
python
辛苦才能29 分钟前
C++ map/set 深度解析:从关联式容器的本质到 operator[] 的三重身份
开发语言·c++
全栈弄潮儿²⁰²⁴31 分钟前
Python实战第2期: 变量与数据类型
python·变量·数据类型·python实战
Chen—LSN44 分钟前
C语言——文件操作(2)
c语言·开发语言·c++·经验分享·笔记·算法·c#
纪念 2291 小时前
C++类和对象(最终篇)
开发语言·c++