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

相关推荐
qq_40698103几秒前
大白话rust系列01注释
开发语言·rust
橘子编程1 分钟前
Java邮件发送全攻略:从入门到实战
java·开发语言·spring boot·spring·spring cloud·maven
dadaobusi5 分钟前
学习:一些互联概念的澄清
学习
Tizzy JJ11 分钟前
Python + pytest 接口自动化测试框架实战:从零搭建企业级项目骨架
开发语言·python·pytest
海兰12 分钟前
【 Python 量化交易】第8章:量化工具箱
开发语言·python
牛油果子哥q14 分钟前
C++大型项目工程精讲:CMake完整实战、静态库&动态库、模块化拆分、单元测试、gdb调试、性能工具、工程踩坑全解
开发语言·c++·单元测试
Dream Cosmos16 分钟前
C++ 多态上篇:从 virtual 到抽象类,彻底理解多态的使用
开发语言·c++
TheBestRucy17 分钟前
Python九阳神功之柒:数据分析三剑客·执剑问道
开发语言·python·数据分析
zyf10441624 分钟前
暑期实践日志 Day45:梳理第五章内容,完善成果总结
学习·计算机网络·剪辑·暑期实践·课题任务