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

相关推荐
用户8356290780513 分钟前
使用 Python 在 Excel 中添加和编辑形状
后端·python
2601_9623004715 分钟前
python在运维上可以干什么,请举几个具体的例子
运维·python·系统管理·网络监控·自动化脚本
小刘在重生~28 分钟前
Java 异常体系完整笔记
java·笔记·python
用户83562907805131 分钟前
使用 Python 为 PDF 添加和管理超链接
后端·python
千千寰宇32 分钟前
[Python/测试] pytest:简洁、可扩展的 Python 测试框架
python·软件质量保障与测试
少陽君33 分钟前
Python 并发编程:IO 等待用线程/asyncio,CPU 计算才用进程
数据库·python·php
aramae40 分钟前
模拟实现strstr函数(C语言)
c语言·开发语言·算法
2601_962284501 小时前
Python 和Java 哪个更适合做自动化测试?
java·自动化测试·python·接口测试·性能测试
liliangcsdn1 小时前
因子权重矩阵处理-滞回缓冲带+降频稳定化动态重选
开发语言·python·算法
ShuiShenHuoLe1 小时前
golang-jwt v5 入门
开发语言·后端·golang