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

相关推荐
吃好睡好便好3 分钟前
用for循环语句求和
开发语言·人工智能·学习·matlab·学习方法
萌新小码农‍3 分钟前
人工智能数学基础+python实例(人工智能学习day3)
开发语言·人工智能·python
Lumbrologist6 分钟前
【C++】零基础入门 · 第 1 节:第一个程序 Hello World 与编译运行
开发语言·c++
超梦dasgg23 分钟前
Java 生产环境 MQ 技术选型全解析
java·开发语言·java-rocketmq·java-rabbitmq
_李小白39 分钟前
【C++学习笔记】新特性之inline变量
c++·笔记·学习
桀人1 小时前
C++——模板初阶(收录在专栏C++入门到精通)
开发语言·c++
一直有一个ac的梦想1 小时前
cmu15445 2025fall lec 18 transactions with two-phase lock
java·开发语言·数据库
毋语天1 小时前
FastAPI 进阶实战:请求体、文件上传、响应模型与数据校验
python·fastapi·api开发·数据校验·pydantic
JAVA社区1 小时前
Java进阶全套教程(四)—— SpringMVC框架详解
java·开发语言·spring·面试·职场和发展