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

相关推荐
程序员爱钓鱼1 分钟前
Python编程实战——Python实用工具与库:Numpy基础
后端·python·面试
程序员霸哥哥3 分钟前
从零搭建PyTorch计算机视觉模型
人工智能·pytorch·python·计算机视觉
2301_7965125213 分钟前
Rust编程学习 - 问号运算符会return一个Result 类型,但是如何使用main函数中使用问号运算符
开发语言·学习·算法·rust
座山雕~19 分钟前
测试接口-----详细
开发语言·postman
deng-c-f28 分钟前
Linux C/C++ 学习日记(47):dpdk(八):UDP的pps测试:内核 VS dpdk
学习
小龙报29 分钟前
算法通关指南:数据结构和算法篇 --- 队列相关算法题》--- 1. 【模板】队列,2. 机器翻译
c语言·开发语言·数据结构·c++·算法·学习方法·visual studio
晚秋大魔王34 分钟前
基于python的jlink单片机自动化批量烧录工具
前端·python·单片机
胖哥真不错35 分钟前
Python基于PyTorch实现多输入多输出进行CNN卷积神经网络回归预测项目实战
pytorch·python·毕业设计·课程设计·毕设·多输入多输出·cnn卷积神经网络回归预测
木木em哈哈36 分钟前
有关于cnb自动化的脚本补全
服务器·开发语言·pygame
星释37 分钟前
Rust 练习册 :Poker与扑克牌游戏
开发语言·游戏·rust