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

相关推荐
meilindehuzi_a13 小时前
从零理解并实现 RAG:用 LangChain.js 构建语义检索问答系统
开发语言·javascript·langchain
风流 少年14 小时前
Julia
开发语言·julia
江畔柳前堤14 小时前
GO01-Go 语言与主流编程语言深度对比
开发语言·人工智能·后端·微服务·云原生·golang·go
:-)15 小时前
算法-归并排序
java·开发语言·数据结构·算法·排序算法
GIS阵地15 小时前
QgsRasterDataProvider 完整详解(QGIS 3.40.13 C++)
开发语言·c++·qt·开源软件·qgis
寒月小酒16 小时前
第三章 索引构建(2-all -in-rag学习)
学习
yaoxin52112316 小时前
462. Java 反射 - 获取声明类与封闭类
java·开发语言·python
天国梦16 小时前
中学生居家英语听力训练深度解析:从核心痛点到AI赋能的全链路方案
人工智能·学习
阿里嘎多学长16 小时前
2026-07-14 GitHub 热点项目精选
开发语言·程序员·github·代码托管
中微极客17 小时前
解锁LLM开发全栈能力:Python + LangChain + RAG 工程实战指南
人工智能·python·langchain