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

相关推荐
Warson_L5 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅5 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅5 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L5 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅6 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L6 小时前
python的类&继承
python
Warson_L6 小时前
类型标注/type annotation
python
ThreeS9 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵10 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏