Python abstract classes 👻

Поділитися
Вставка
  • Опубліковано 11 лис 2024

КОМЕНТАРІ • 158

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

    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 2 роки тому +66

    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 роки тому +48

    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.

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

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

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

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

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

    Thanks. Finally I understand now the importance usage of abstract

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

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

  • @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.

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

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

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

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

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

    Nice brief description of the essentials -- thanks!

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

    best explanation of abstraction in python on youtube

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

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

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

    Great explanation an example, very easy to understand!

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

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

  • @MissMisc-n3d
    @MissMisc-n3d 7 місяців тому

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

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

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

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

    Nice job! Easy to follow examples!

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

    very understandable

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

    Thank you for this video! Amazing explanation

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

    Loving these short conceptual videos 😁😁❤❤

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

    Great tutorial! Thanks a lot, bro! ;)

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

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

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

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

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

    Really helpful! Thanks!!

  • @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

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

    Thank you for this lessons

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

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

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

    Really nice, concise, and clear

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

    Bless you for making this more clear than my professor.

  • @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.

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

    A very clear explanation. Thanks!

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

    Thank you sir!

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

    Awesome tutorial, thanks

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

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

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

    Great explanation bro! Thanks!

  • @hrushikeshsahasrabuddhe5103

    Simple & to the point!

  • @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

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

    I'm really liking your python tutorials

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

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

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

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

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

    Excellent explanation, thanks!

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

    excellent explanation
    keep it up

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

    Nicely explained! Thanks :)

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

    It's easy to understand the concept.

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

    Very nice and useful video

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

    It's amazing!Thank you

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

    Best explanation.

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

    More content on abstraction and encapsulation while using dataclasses please

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

    Thanks alot ❤️

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

    Wow!

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

    Great discussion Bro

  • @abdulhameedmalik4299
    @abdulhameedmalik4299 19 днів тому

    Best example

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

    You teach nice

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

    awesome video

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

    Lovely

  • @ImranAli-wh4rw
    @ImranAli-wh4rw 2 дні тому

    Amazing

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

    Great!

  • @SuperMaker.M
    @SuperMaker.M 11 місяців тому

    great video !

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

    Thanks alot.🙏

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

    great video!!

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

    Thank you!!!

  • @ВаняМихнюк-ш9д
    @ВаняМихнюк-ш9д 5 місяців тому

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

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

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

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

    Thank you Bro!

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

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

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

    you are a genius bro. thanks 🙂

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

    You are just amazing bro

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

    Thank you

  • @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!

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

    NIce!

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

    quick and dirty.
    nice, thanks!

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

    for the algorithms. ty brother

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

    Hi bro nice video

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

    Thanks

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

    Thanks Bro!

  • @HussainAli-sb1dv
    @HussainAli-sb1dv Рік тому

    love u

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

    supporting the channel

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

    thanks bro

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

    Thanks!

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

    Instant like for mentioning the need for speed:)

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

    Best tutorial I have ever seen

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

    thaaaanks

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

    nice

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

    Clear as water!!!

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

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

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

    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?

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

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

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

    from abc import ABC,abstractmethod
    class Animal(ABC):
    @abstractmethod
    def eat(self):
    print("This is eating something")
    class Rabbit(Animal):
    def eat(self):
    print("This is eating grass")

    obj=Rabbit()
    obj.eat()

  • @JosédaSilva-z5y
    @JosédaSilva-z5y 7 місяців тому

    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.

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

    best BRO :)

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

    thank you!

  • @shingaling3315
    @shingaling3315 Рік тому +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

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

    thank you bro !

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

    ty bro

  • @samiam.402
    @samiam.402 3 роки тому +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 3 роки тому +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

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

    Thx bro!

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

    Thank youu!!!

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

    I'm so freaking stinky it's insane and incomprehensible how much I'm smelly

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

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