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

相关推荐
罗罗攀7 分钟前
PyTorch学习笔记|张量的广播和科学运算
人工智能·pytorch·笔记·python·学习
m0_459252468 分钟前
fastadmin动态渲染统计信息
开发语言·前端·javascript·php
CDA数据分析师干货分享24 分钟前
汉江师范学院数据科学与大数据技术专业大二学生:CDA一级学习经验
大数据·经验分享·学习·数据分析·cda证书·cda数据分析师
傻啦嘿哟27 分钟前
Python 操作 Excel 条件格式指南
开发语言·python·excel
SuniaWang27 分钟前
《Spring AI + 大模型全栈实战》学习手册系列 · 专题四:《Ollama 模型管理与调优:让 AI 模型在低配服务器上流畅运行》
人工智能·学习·spring
逆境不可逃27 分钟前
LeetCode 热题 100 之 33. 搜索旋转排序数组 153. 寻找旋转排序数组中的最小值 4. 寻找两个正序数组的中位数
java·开发语言·数据结构·算法·leetcode·职场和发展
2301_8073671928 分钟前
Python日志记录(Logging)最佳实践
jvm·数据库·python
2301_7957417939 分钟前
构建一个基于命令行的待办事项应用
jvm·数据库·python
星空下的月光影子41 分钟前
易语言开发从入门到精通:进阶篇·数据处理与分析自动化·高频刚需手工转自动场景全覆盖
开发语言
林夕sama43 分钟前
多线程基础(四)
java·开发语言