Python类巩固
发布日期:2021-05-14 17:04:21 浏览次数:18 分类:精选文章

本文共 1838 字,大约阅读时间需要 6 分钟。

<Class(Class): ������������������������������������������������������������������������������������������������������������������������>

<������(Instance): ���������������������������>

<������(Methods): ������������������������>

<������������

:**

<���������������������������������������������__init__()������������������������������������������������������������������>

<���������self���������������������������������������������������������������������������������������������������������������������������������>

<���self���������������������������������������������������������������������>

<���������������������������������������������������������������������������������������>

<���������������������������������������������������������������������������������������������������������������������������������������������������>

<������������super()���������������������������������>

<���������������������������������������������������������������������������������������������������������������������������������������������������������������������

class Car: def init(self, make, model, year): self.ma = make self.mod = model self.ye = year self.gas = 100

def get_descriptive_name(self):
long_name = f"{self.ye} {self.ma} {self.mod}"
return long_name.title()
def fill_gas_tank(self):
print(f"The tank is only {self.gas} gas")

class ElectricCar(Car): def init(self, make, model, year): super().init(make, model, year) def fill_gas_tank(self): print("This car doesn't need a gas tank!")

my_car = ElectricCar('teals', 'model s', 2020) my_car.fill_gas_tank()

car = Car('audi', 'A8L', 2021) car.fill_gas_tank()

���������������Uh������������������������������

<���������������������������:>

������������������������������������������������������������������������������������������������������������������������������������

上一篇:最大的和
下一篇:二分查找板子

发表评论

最新留言

不错!
[***.144.177.141]2025年04月22日 11时08分52秒