面向对象 - 继承
基本类(超类)包含了共有的属性和方法,导出类(子类)可以分别添加各自独有的属性和方法。
在线运行演示代码
参考教程
class Vehicle: speed = 60.0 def drive(self, distance): time = distance / self.speed print(time) class Bike(Vehicle): speed = 25.0 class Train(Vehicle): speed = 200.0 fuel = 500.0 bike = Bike() bike.drive(1000.0) train = Train() train.drive(1000.0) print(train.fuel)