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

相关推荐
先做个垃圾出来………12 分钟前
Python中使用pandas
开发语言·python·pandas
DanmF--22 分钟前
C#面向对象实践项目--贪吃蛇
开发语言·游戏·c#·游戏程序
爱意随风起风止意难平29 分钟前
003 flutter初始文件讲解(2)
学习·flutter
东京老树根32 分钟前
SAP学习笔记 - 开发18 - 前端Fiori开发 应用描述符(manifest.json)的用途
笔记·学习
@老蝴34 分钟前
C语言 — 动态内存管理
android·c语言·开发语言
不爱吃山楂罐头1 小时前
第三十三天打卡复习
python·深度学习
虾球xz1 小时前
CppCon 2014 学习:C++ Memory Model Meets High-Update-Rate Data Structures
java·开发语言·c++·学习
小灰灰搞电子1 小时前
Qt 仪表盘源码分享
开发语言·qt
水水沝淼㵘1 小时前
嵌入式开发学习日志(linux系统编程--系统编程之 进程间通信IPC)Day32
linux·运维·学习
我的golang之路果然有问题1 小时前
快速了解GO+ElasticSearch
开发语言·经验分享·笔记·后端·elasticsearch·golang