Python How to inherit a class, Inheritance Basics - Python programming for beginners.

Publicado el: 01 diciembre 2022
en el canal de: Brendan Callaghan
160
2

Python Inheritance - In this video I discuss the basics of inheritance in python and how it works
Music:-
Music by Bensound, www.bensound.com

class Vehicle:
def __init__(self, name, speed):
self.name = name
self.speed = speed

def acceleration(self):
self.speed += 5

def brake(self):
self.speed -= 5


class Car(Vehicle):
def __init__(self, name, speed, engine_capacity):
Vehicle.__init__(self, name, speed)
self.engine_capacity = engine_capacity

def display_car(self):
print(f"The cars name is {self.name}")
print(f"The cars speed is {self.speed}")
print(f"The cars engine capacity is {self.engine_capacity}")


class Truck(Vehicle):
def __init__(self, name, speed, engine_capacity):
Vehicle.__init__(self, name, speed)
self.engine_capacity = engine_capacity

def display_truck(self):
print(f"The trucks name is {self.name}")
print(f"The trucks speed is {self.speed}")
print(f"The trucks engine capacity is {self.engine_capacity}")

from vehicle import Car, Truck

car = Car("Lightening McQueen", 200, 2000)
truck = Truck("Fire Truck",100, 3500)

car.display_car()
car.acceleration()
car.acceleration()
car.brake()
car.display_car()

truck.display_truck()
truck.brake()
truck.display_truck()


En esta página del sitio puede ver el video en línea Python How to inherit a class, Inheritance Basics - Python programming for beginners. de Duración hora minuto segunda en buena calidad , que subió el usuario Brendan Callaghan 01 diciembre 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 160 veces y le gustó 2 a los espectadores. Disfruta viendo!