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

相关推荐
Aurorar0rua几秒前
CS50 x 2024 Notes C - 09
c语言·开发语言·学习方法
兔小盈3 分钟前
多线程篇-(二)线程创建、中断与终止
java·开发语言·多线程
knight_9___11 分钟前
LLM工具调用面试篇6
人工智能·python·面试·职场和发展·llm·agent
用户39626910600312 分钟前
asyncio + subprocess:Python异步调用外部命令踩坑实录
python
hoiii18712 分钟前
基于MATLAB实现内点法解决凸优化问题
开发语言·matlab
AI砖家24 分钟前
Claude Code Superpowers 安装使用指南:让 AI 编程从“业余”走向“工程化”
前端·人工智能·python·ai编程·代码规范
承渊政道40 分钟前
【动态规划算法】(完全背包问题从状态定义到空间优化)
数据结构·c++·学习·算法·leetcode·动态规划·哈希算法
计算机毕业编程指导师41 分钟前
【计算机毕设推荐】Python+Spark卵巢癌风险数据可视化系统完整实现 毕业设计 选题推荐 毕设选题 数据分析 机器学习 数据挖掘
hadoop·python·计算机·数据挖掘·spark·毕业设计·卵巢癌
玩转单片机与嵌入式43 分钟前
学习嵌入式AI(TInyML),只需掌握这点python基础即可!
人工智能·python·学习