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

相关推荐
带土112 分钟前
4. C++ static关键字
开发语言·c++
C++ 老炮儿的技术栈19 分钟前
什么是通信规约
开发语言·数据结构·c++·windows·算法·安全·链表
@大迁世界22 分钟前
TypeScript 的本质并非类型,而是信任
开发语言·前端·javascript·typescript·ecmascript
栗子叶28 分钟前
Java对象创建的过程
java·开发语言·jvm
GIS之路31 分钟前
GDAL 实现矢量裁剪
前端·python·信息可视化
Amumu1213837 分钟前
React面向组件编程
开发语言·前端·javascript
学历真的很重要37 分钟前
LangChain V1.0 Context Engineering(上下文工程)详细指南
人工智能·后端·学习·语言模型·面试·职场和发展·langchain
IT=>小脑虎38 分钟前
Python零基础衔接进阶知识点【详解版】
开发语言·人工智能·python
智航GIS40 分钟前
10.6 Scrapy:Python 网页爬取框架
python·scrapy·信息可视化
wjs202440 分钟前
C 标准库 - `<float.h>》详解
开发语言