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

相关推荐
毅炼4 分钟前
Java 集合常见问题总结(3)
java·开发语言·后端
崎岖Qiu10 分钟前
【计算机网络 | 第十一篇】图解交换机的自学习功能
网络·学习·计算机网络
沐知全栈开发14 分钟前
ionic 对话框:深度解析与最佳实践
开发语言
Jia ming21 分钟前
《智能法官软件项目》—罪名初判模块
python·教学·案例·智能法官
Jia ming37 分钟前
《智能法官软件项目》—法律文书生成模块
python·教学·案例·智能法官软件
科技林总41 分钟前
【系统分析师】8.0 项目管理
学习
曦月逸霜1 小时前
Python数据分析——个人笔记(持续更新中~)
python
海棠AI实验室1 小时前
第六章 从“能用”到“能交付”的关键一刀:偏好对齐(Preference Alignment)数据工程
python·私有模型训练
浅念-1 小时前
C++ string类
开发语言·c++·经验分享·笔记·学习
百锦再1 小时前
Java多线程编程全面解析:从原理到实战
java·开发语言·python·spring·kafka·tomcat·maven