Python类学习4
2021/7/15 20:07:00
本文主要是介绍Python类学习4,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
class Car : def __init__ (self,make,model,year): self.make = make self.model = model self.year = year self.odmoeter = 2 self.gas_tank_L = 50 def get_descriptive_name (self): long_name = f"{self.year}{self.make}{self.model},{self.odmoeter}" return long_name.title() def update_odmoeter(self,milage): if milage >= 0 : self.odmoeter += milage else: print("WARNING!你没有权限执行该操作") def gas_tank_size(self): print(self.gas_tank_L) """ yy_car =Car("奥迪","A6",2021) print(yy_car.gas_tank_size()) """ class Battery: def __init__(self,battery,battery_size=75): self.battery_size = battery_size self.battery = battery def describe_battery(self): print (f"the battery was made for {self.battery}") def describe_battery_size(self): print(f"the car have {self.battery_size} -kwh battery") class ElectricCar(Car): def __init__(self, make, model, year): super().__init__(make, model, year) self.battery = Battery() ##为啥呢 def gas_tank(self): pass my_car = ElectricCar("tesla","models",1010) print(my_car.gas_tank()) print(my_car.get_descriptive_name())
这篇关于Python类学习4的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享