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 分钟前
LangChain 基于 Python 的技术- agent模块使用总结
开发语言·python·langchain
GEO从入门到精通3 分钟前
GEO学习与传统SEO学习有什么区别?
人工智能·学习·microsoft
weixin_386468968 分钟前
openharmony 6.0编译rk3568过程记录
c语言·c++·git·python·vim·harmonyos·openharmony
雪度娃娃12 分钟前
转向现代C++——优先选用别名声明,而非 typedef
开发语言·c++
沐知全栈开发13 分钟前
PHP While 循环
开发语言
其实防守也摸鱼14 分钟前
upload-labs靶场的pass-13~21的解题步骤及原理讲解
python·安全·网络安全·靶场·二进制·文件上传漏洞·文件包含漏洞
俊哥工具22 分钟前
不用安装不收费!多功能U盘修复工具,解决大部分U盘故障
学习·pdf·word·excel·音视频
Data_Journal23 分钟前
什么是数据采购,它究竟如何运作?
大数据·开发语言·数据库·人工智能·python
Gigavision25 分钟前
SEED-VII 数据集介绍:面向七类情绪识别的 EEG 与眼动多模态数据集
人工智能·python·算法·脑机接口
_Evan_Yao28 分钟前
大学自学能力怎么练?慕课、B站、书籍资源清单
后端·学习