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.带输入参数的线程启动 C# + WPF 完整示例
开发语言·前端·c#·.net·wpf
来自远方的老作者几秒前
第9章 函数-9.9 函数式编程
python·函数·回调函数·lambda表达式·函数闭包·偏函数·函数装饰器
爱学习的小可爱卢1 分钟前
算法—Java Map 核心方法与实战场景指南
java·开发语言·算法
X1A0RAN2 分钟前
容器化部署elasticsearch教程+python操作es数据库示例
数据库·python·elasticsearch
weixin_580614002 分钟前
Go语言怎么优化goroutine_Go语言goroutine优化教程【基础】
jvm·数据库·python
豆豆3 分钟前
建站系统怎么选?2026年SaaS平台与开源CMS对比分析
java·开发语言·开源·cms·网站建设·网站制作·网站开发
神仙别闹3 分钟前
基于C++实现的简单的SMTP服务器
服务器·开发语言·c++
Ulyanov3 分钟前
ZeroMQ在分布式雷达仿真中的应用
分布式·python·信号处理·系统仿真·雷达电子对抗
遗憾随她而去.6 分钟前
react学习(一)
javascript·学习·react.js