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

相关推荐
Rolei_zl11 分钟前
AIGC(生成式AI)试用 41 -- 程序(Python + OCR)-3
python·aigc
eybk12 分钟前
使用Beeware开发文件浏览器获取Android15的文件权限
python
CryptoRzz16 分钟前
印度股票数据 PHP 对接文档 覆盖 BSE(孟买证券交易所)和 NSE(印度国家证券交易所)的实时数据
android·服务器·开发语言·区块链·php
lkbhua莱克瓦2418 分钟前
集合进阶6——TreeMap底层原理
java·开发语言·笔记·学习方法·hashmap
普通网友21 分钟前
内存对齐与缓存友好设计
开发语言·c++·算法
T***u33324 分钟前
后端缓存技术学习,Redis实战案例
redis·学习·缓存
lsx20240627 分钟前
DOM 节点信息
开发语言
柒柒钏35 分钟前
VSCode 终端配置与 Python 虚拟环境使用指南
ide·vscode·python
普通网友44 分钟前
C++编译期数据结构
开发语言·c++·算法
Gorgous—l1 小时前
数据结构算法学习:LeetCode热题100-图论篇(岛屿数量、腐烂的橘子、课程表、实现 Trie (前缀树))
数据结构·学习·算法