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

相关推荐
不懒不懒1 分钟前
【卷积神经网络作业实现人脸的关键点定位功能】
开发语言·python
321.。1 分钟前
Linux 进程控制深度解析:从创建到替换的完整指南
linux·开发语言·c++·学习
酉鬼女又兒5 分钟前
零基础快速入门前端Web存储(sessionStorage & localStorage)知识点详解与蓝桥杯考点应用(可用于备赛蓝桥杯Web应用开发)
开发语言·前端·javascript·职场和发展·蓝桥杯·html
Bert.Cai6 分钟前
Python集合简介
开发语言·python
tryCbest10 分钟前
Java和Python开发项目部署简介
java·开发语言·python
ZTLJQ10 分钟前
任务调度的艺术:Python分布式任务系统完全解析
开发语言·分布式·python
阿里嘎多学长12 分钟前
2026-03-31 GitHub 热点项目精选
开发语言·程序员·github·代码托管
CheerWWW15 分钟前
C++学习笔记——枚举、继承、虚函数、可见性
c++·笔记·学习
敏编程17 分钟前
一天一个Python库:isodate - 处理 ISO 8601 日期时间格式
python
小只笨笨狗~20 分钟前
解决objectSpanMethod与expand共存时展开后表格错位问题
开发语言·javascript·ecmascript