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

相关推荐
deepxuan1 分钟前
Day2--python三大库-numpy
开发语言·python·numpy
徐同保4 分钟前
python如何手动抛出异常
java·前端·python
AD钙奶-lalala11 分钟前
Android编译C++代码步骤详解
android·开发语言·c++
中科三方22 分钟前
域名注册后无法解析解决方法:技术故障排查和解决指南
开发语言·github·php
极客先躯36 分钟前
高级java每日一道面试题-2025年7月02日-基础篇[LangChain4j]-什么是 AiServices?它是如何简化 LLM 应用开发的?
java·开发语言
被遗忘在角落的死小孩1 小时前
抗量子 Winternitz One Time Signature(OTS) 算法学习
学习·算法·哈希算法
浅念-1 小时前
C++ :类和对象(4)
c语言·开发语言·c++·经验分享·笔记·学习·算法
lly2024062 小时前
Docker 安装 Python
开发语言
道法自然|~2 小时前
BugkuCTF栅栏密码解题记录(原理+C语言实现)
c语言·开发语言
Dxy12393102162 小时前
Python检查JSON格式错误的多种方法
前端·python·json