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

相关推荐
喵手8 分钟前
Python爬虫实战:构建各地统计局数据发布板块的自动化索引爬虫(附CSV导出 + SQLite持久化存储)!
爬虫·python·爬虫实战·零基础python爬虫教学·采集数据csv导出·采集各地统计局数据发布数据·统计局数据采集
寻寻觅觅☆30 分钟前
东华OJ-基础题-104-A == B ?(C++)
开发语言·c++
lightqjx40 分钟前
【C++】unordered系列的封装
开发语言·c++·stl·unordered系列
天天爱吃肉82181 小时前
跟着创意天才周杰伦学新能源汽车研发测试!3年从工程师到领域专家的成长秘籍!
数据库·python·算法·分类·汽车
zh_xuan1 小时前
kotlin lazy委托异常时执行流程
开发语言·kotlin
Ziky学习记录1 小时前
从零到实战:React Router 学习与总结
前端·学习·react.js
m0_715575341 小时前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python
甄心爱学习1 小时前
【leetcode】判断平衡二叉树
python·算法·leetcode
深蓝电商API1 小时前
滑块验证码破解思路与常见绕过方法
爬虫·python
阿猿收手吧!1 小时前
【C++】string_view:高效字符串处理指南
开发语言·c++