Python abstract classes 👻

Поділитися
Вставка
  • Опубліковано 3 січ 2021
  • 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: bit.ly/2JnDfCE
    Music promoted by Audio Library • Up In My Jam (All Of A...
    ===========================================================
  • Наука та технологія

КОМЕНТАРІ • 152

  • @BroCodez
    @BroCodez  3 роки тому +44

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

  • @shrikanthsingh8243
    @shrikanthsingh8243 Рік тому +60

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

  • @forrestelliott3267
    @forrestelliott3267 2 роки тому +43

    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.

  • @yevhenliubarskyi1841
    @yevhenliubarskyi1841 2 роки тому +7

    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.

  • @yuilhan4275
    @yuilhan4275 3 роки тому +9

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

  • @guardmanbob
    @guardmanbob 3 роки тому +6

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

  • @svensalvatore8702
    @svensalvatore8702 Рік тому

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

  • @ravikanthduvvuri392
    @ravikanthduvvuri392 2 роки тому +4

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

  • @simeonbogg3725
    @simeonbogg3725 2 роки тому

    Great explanation an example, very easy to understand!

  • @roxykvarman8773
    @roxykvarman8773 3 роки тому +2

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

  • @גייסוןחן
    @גייסוןחן Місяць тому

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

  • @trippingwithcrujo7708
    @trippingwithcrujo7708 Рік тому +1

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

  • @otsapin
    @otsapin 3 роки тому +2

    Great tutorial! Thanks a lot, bro! ;)

  • @jackb4223
    @jackb4223 3 роки тому +1

    Nice brief description of the essentials -- thanks!

  • @erickonyanda5570
    @erickonyanda5570 3 роки тому +1

    Thank you very much. Wow!! Very simple, very easy, very clear explanation

  • @stevechesney9334
    @stevechesney9334 Рік тому

    Nice job! Easy to follow examples!

  • @RajatSadanandan
    @RajatSadanandan 3 роки тому +2

    Really helpful! Thanks!!

  • @softwareengineer8923
    @softwareengineer8923 2 місяці тому

    Awesome tutorial, thanks

  • @hooman3669
    @hooman3669 Місяць тому

    Loving these short conceptual videos 😁😁❤❤

  • @davidstefanov9210
    @davidstefanov9210 3 роки тому +1

    Thank you for the video dude,It was very helpful and informative. BTW my Teacher linked this video in our Python course as a example

  • @linatroshka
    @linatroshka Рік тому

    Very clear and concise explanation. Thank you very much for this!

  • @liasantos6639
    @liasantos6639 7 місяців тому

    Thank you for this video! Amazing explanation

  • @joelpaquete4152
    @joelpaquete4152 2 роки тому

    Thank you for this lessons

  • @zacky7862
    @zacky7862 2 роки тому +2

    Thanks. Finally I understand now the importance usage of abstract

  • @akramal-fageeh8969
    @akramal-fageeh8969 2 місяці тому

    Really nice, concise, and clear

  • @d1jn
    @d1jn 2 роки тому +1

    Great explanation bro! Thanks!

  • @greenstreet704
    @greenstreet704 Рік тому

    great video!!

  • @davidrowlands8548
    @davidrowlands8548 2 роки тому

    Thank you I was able to understand this concept thanks to your video.

  • @MrPimleemans
    @MrPimleemans Рік тому

    Excellent explanation, thanks!

  • @macieks3604
    @macieks3604 Рік тому

    Nicely explained! Thanks :)

  • @Techieinla
    @Techieinla 3 роки тому +3

    very understandable

  • @83sal
    @83sal 3 роки тому +2

    Thank you sir!

  • @Ronnie9P
    @Ronnie9P 2 роки тому +1

    best explanation of abstraction in python on youtube

  • @cesarosantini708
    @cesarosantini708 3 роки тому +2

    excellent explanation
    keep it up

  • @user-mq9hf1mm9f
    @user-mq9hf1mm9f 4 місяці тому

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

  • @myoutube8832
    @myoutube8832 5 місяців тому

    Great discussion Bro

  • @pablocesarlopez7379
    @pablocesarlopez7379 Рік тому

    A very clear explanation. Thanks!

  • @priyanshagarwal1565
    @priyanshagarwal1565 4 місяці тому

    You teach nice

  • @nishantrandev9633
    @nishantrandev9633 2 роки тому

    Great video. To the point. That's how the content should be created. Thanks!

  • @hiiexisthiiexist1284
    @hiiexisthiiexist1284 Рік тому

    awesome video

  • @streamindigoflags8035
    @streamindigoflags8035 10 місяців тому

    Hi bro nice video

  • @andrewv8350
    @andrewv8350 8 днів тому

    Now, it's clear for me. Thanks a lot, bro!

  • @SuccessXcel_
    @SuccessXcel_ 11 місяців тому

    Best explanation.

  • @Franco-ss4bu
    @Franco-ss4bu 7 місяців тому

    I'm really liking your python tutorials

  • @sahilsagwekar
    @sahilsagwekar Рік тому +2

    thanks bro

  • @reshmi003
    @reshmi003 Рік тому +1

    Thanks alot ❤️

  • @kemann3815
    @kemann3815 2 роки тому

    Lovely

  • @user-yu1dc7su2r
    @user-yu1dc7su2r 10 місяців тому

    Thanks alot.🙏

  • @hrushikeshsahasrabuddhe5103
    @hrushikeshsahasrabuddhe5103 9 місяців тому

    Simple & to the point!

  • @theverynvg
    @theverynvg Рік тому

    It's amazing!Thank you

  • @igordjokic
    @igordjokic Рік тому

    NIce!

  • @woltron4o
    @woltron4o 2 роки тому

    Very nice and useful video

  • @abdullahnasir8535
    @abdullahnasir8535 9 місяців тому

    You are just amazing bro

  • @Muertedertod
    @Muertedertod 2 роки тому

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

  • @beingzero7541
    @beingzero7541 2 роки тому +1

    Wow!

  • @horoshuhin
    @horoshuhin 2 роки тому

    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

  • @henriquefelinimena7433
    @henriquefelinimena7433 3 роки тому +2

    Thank you Bro!

  • @nirutg5130
    @nirutg5130 Рік тому

    I find 6-7 sources from internet to understand about Python abstraction but not understand!, just understand from this video. Thank you so much Bro.

  • @sirenhanced6248
    @sirenhanced6248 Рік тому

    Thanks so much I have a test for my Python OOP course tomorrow on this you saved me.

  • @TheHansdampf80
    @TheHansdampf80 6 місяців тому

    Thank you

  • @Vertig_Pro
    @Vertig_Pro Рік тому

    Keep doing gods work bro

  • @soklin
    @soklin Рік тому

    Thank you!!!

  • @HussainAli-sb1dv
    @HussainAli-sb1dv 9 місяців тому

    love u

  • @EissaAlahdul
    @EissaAlahdul 2 роки тому

    Thanks!

  • @Amirkolo
    @Amirkolo 5 місяців тому

    you are a genius bro. thanks 🙂

  • @tarikyassa1076
    @tarikyassa1076 3 роки тому +1

    Thanks Bro!

  • @fellowstepchicken7555
    @fellowstepchicken7555 8 місяців тому

    Thanks bud !

  • @rubenc4696
    @rubenc4696 3 місяці тому

    Thanks

  • @shavindasilva
    @shavindasilva 2 роки тому

    best BRO :)

  • @SmokyDesperado91
    @SmokyDesperado91 2 роки тому +1

    Thank you, great explanation! I have one question though: is there some way to create abstract attributes in analogy to abstract methods? I want to make sure that those attributes will be implemented in all child classes

  • @timhiggins7072
    @timhiggins7072 9 місяців тому

    Bless you for making this more clear than my professor.

  • @anfedres
    @anfedres 3 роки тому +2

    cool video bro... ps: Turn of the cc... it is hilarious!

  • @uuhju7004
    @uuhju7004 3 роки тому

    nice

  • @chriskeo392
    @chriskeo392 Рік тому

    More content on abstraction and encapsulation while using dataclasses please

  • @harithabandara3212
    @harithabandara3212 Рік тому

    Thank youu!!!

  • @hangchen
    @hangchen 9 місяців тому

    Thx bro!

  • @marianotorres4052
    @marianotorres4052 Рік тому

    thank you!

  • @jimenadelgado7384
    @jimenadelgado7384 4 місяці тому

    thaaaanks

  • @digosantista
    @digosantista 2 роки тому

    Cool. But it would be nice to comment on the video (or do a voice over) to let people know that error arouse from Vehicle being instatiated not from implementation itself.
    Other than that, great! Thanks!

  • @jhontriboyke5534
    @jhontriboyke5534 4 місяці тому

    thank you bro !

  • @cloudroot7
    @cloudroot7 2 роки тому

    It's easy to understand the concept.

  • @user-cd4zb3gk3z
    @user-cd4zb3gk3z Місяць тому

    Спасибо, видео помогло разобраться!

  • @chillydoog
    @chillydoog 9 місяців тому

    for the algorithms. ty brother

  • @pun15h3r.
    @pun15h3r. 4 місяці тому

    quick and dirty.
    nice, thanks!

  • @omercagla8970
    @omercagla8970 Рік тому

    Best tutorial I have ever seen

  • @lw9954
    @lw9954 Рік тому

    ty bro

  • @xBaphometHx
    @xBaphometHx Рік тому

    Clear as water!!!

  • @kerry7932
    @kerry7932 8 місяців тому

    Nice video. I think we need some additional information about the purpose of abstract classes as many of the comments have indicated. That is, is if subclasses cannot inherit from their parent, what is the purpose of the parent?

  • @lovelyaashik9732
    @lovelyaashik9732 2 роки тому +3

    Sir basically what's the use of it , for what. Purpose we're going to use it

  • @Bro-cc8pw
    @Bro-cc8pw 22 дні тому

    What's up bro

  • @user-ew7ri4gk2l
    @user-ew7ri4gk2l 3 місяці тому

    You are very clear and objective. But I can't understand the use of abstract class if you can't instantiate it and the same functions are written bellow in other classes???
    Thanks in advance.

  • @santosbogo
    @santosbogo Рік тому

    I am doing python at university and this is the best video Ive ever watch

  • @nazarsilchenko8326
    @nazarsilchenko8326 2 роки тому

    Instant like for mentioning the need for speed:)

  • @samiam.402
    @samiam.402 2 роки тому +5

    I might've missed it, did he explain why you don't have to "super()" the methods you are overriding? Is this an inherent part of an abstract class, or am I missing something?

    • @Craulback
      @Craulback 2 роки тому +3

      super() gets the child class access to the attributes from the parents method, it doesn't override anything, but is useful when your child class needs the same attributes, plus some new one.
      class Child(Parent)
      def __init__(self,attribute_1,attribute_2,attribute_3)
      super().__init__(attribute_1,attribute_2) # this will pull the first 2 attributes (of the same name) from the parent
      as for overriding, just defining the child's method using the same name as the one in the parent will override it for the child class.
      it looks for the "go()" method in the child class, before looking for the one from the parent.
      so it never actually encounters the abstract version of the method.

    • @sebastianradlmeier8922
      @sebastianradlmeier8922 2 роки тому +1

      ​@@Craulback Thanks for the explanation

  • @shingaling3315
    @shingaling3315 11 місяців тому +1

    I understand the implementation but what is the purpose of doing this? I’m not following what benefit was gained by going through this versus not defining an abstract class at all

  • @sterlingevans129
    @sterlingevans129 Рік тому +2

    Can someone explain the reason an abstract class would be needed if the child class' methods would be explicitly written anyway?

  • @jhassee
    @jhassee Рік тому

    supporting the channel

  • @vitaliytysiachnyk5347
    @vitaliytysiachnyk5347 11 місяців тому

    Bro, please add English subtitles, because it's only Vietnam. Lol
    Thank you!

  • @SxlarSiren
    @SxlarSiren Рік тому

    WE LOVE YOU

  • @gattinocurioso6852
    @gattinocurioso6852 9 місяців тому

    In python can you explain the difference from Abstract class and Interface?