Python abstract classes 👻

Опубликовано: 04 Январь 2021
на канале: Bro Code
79,495
4.2k

Python abstract class example tutorial explained

#python #abstract #classes

#abstract class = a class which contains one or more abstract methods.
#abstract method = a method that has a declaration but does not have an implementation.

prevents a user from creating an object of that class
+ compels a user to override abstract methods in a child class

from abc import ABC, abstractmethod

class Vehicle(ABC):

@abstractmethod
def go(self):
pass

@abstractmethod
def stop(self):
pass

class Car(Vehicle):

def go(self):
print("You drive the car")

def stop(self):
print("This car is stopped")

class Motorcycle(Vehicle):

def go(self):
print("You ride the motorcycle")

def stop(self):
print("This motorcycle is stopped")


#vehicle = Vehicle()
car = Car()
motorcycle = Motorcycle()

#vehicle.go()
car.go()
motorcycle.go()

#vehicle.stop()
car.stop()
motorcycle.stop()

music credits 🎼 :
===========================================================
Up In My Jam (All Of A Sudden) by - Kubbi   / kubbi  
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
Free Download / Stream: http://bit.ly/2JnDfCE
Music promoted by Audio Library    • Up In My Jam (All Of A Sudden) – Kubb...  
===========================================================


На этой странице сайта вы можете посмотреть видео онлайн Python abstract classes 👻 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Bro Code 04 Январь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 79,495 раз и оно понравилось 4.2 тысяч зрителям. Приятного просмотра!