Python abstract classes 👻

preview_player
Показать описание
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()

music credits 🎼 :
===========================================================
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
===========================================================
Рекомендации по теме
Комментарии
Автор

TLDR

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

# 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.

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()

BroCodez
Автор

Your intentions are clear - Simply educate and not show off smartness by complicating the content, which other channels do. Keep up your work.

shrikanthsingh
Автор

This was really helpful, thank you. Though I think at 4:57 the error arose from the vehicle = Vehicle() line, not from the motorcycle = Motorcycle() line, as your commentary implies at that moment.

forrestelliott
Автор

straight to the point, clear, and fun to watch. will binge all ur videos

guardmanbob
Автор

Thank you, your explanations are clear and is easy enough to understand.

yuilhan
Автор

Really simple and straight to the point. Makes it easier to understand more complicated applications later on. Good job!

trippingwithcrujo
Автор

Thank you Bro, your explanations are just crystal clear. I've already watched several of your videos. Hope you achieve great success with your channel.

yevhenliubarskyi
Автор

Omg, can I just say you are saving my life rn? Thank you for this clear and concise lesson - thank you SO much.

MissMisc-nd
Автор

helped a lot on the basic understanding of the abstract class, which is exactly what I needed for my study, thank you! :)

גייסוןחן
Автор

Thanks. Finally I understand now the importance usage of abstract

zacky
Автор

finally someone that is able to explain this clear and short! THX a lot!

Muertedertod
Автор

best explanation of abstraction in python on youtube

RonnieP
Автор

I got best content thanks for your best class bro☺️☺️

ravikanthduvvuri
Автор

Nice brief description of the essentials -- thanks!

jackb
Автор

Bless you for making this more clear than my professor.

timhiggins
Автор

Great tutorial! Thanks a lot, bro! ;)

otsapin
Автор

Thanks a lot! Great explanation! Subscribed and going to take your python and javascript crash courses!

roxykvarman
Автор

this is such a concise and to-the-point explanation of ABC. I've yet to find a better one. and probably don't need to anyway. thank you

horoshuhin
Автор

Loving these short conceptual videos 😁😁❤❤

hooman
Автор

This is soo Good of a video and explanation. Thank you, sir!

svensalvatore