Python OOP Tutorial 4: Inheritance - Creating Subclasses

Sdílet
Vložit
  • čas přidán 5. 09. 2024

Komentáře • 1,2K

  • @scorpp149
    @scorpp149 Před 7 lety +922

    omg...it's like you are ansewring our questions before we even ask them..brilliant thank you very much

    • @josecruz2574
      @josecruz2574 Před 4 lety +13

      Yes. Wow. Perfect walk through. 10/10 quality. I cant get off this channel.

    • @tommyl3707
      @tommyl3707 Před 3 měsíci +1

      Honestly I was getting a lot of anxiety from watching subpar DataCamp courses and wanting to quit coding until I found these videos

  • @user-xc5xf8gp8n
    @user-xc5xf8gp8n Před 4 lety +780

    Corey talks about inheritance of classes in this video.
    1. What is inheritence?
    It is a method that allows us to create a new class that shares the same attributes and method with the original function, and add some extra functionality to the new class. It also does not disturb the original class.
    2. How to make a class inherit from another class?
    class Developer(Employee):
    3. Structure of classes and subclasses.
    When we input a function to a subclass, python follows the 'method resolution order', which is the chain of classes that it goes through to find what the method is. All classes have the built-in group of methods and attributes as their primary order.
    4. How to initiate the subclass so that it can handle more information than its original class can?
    There are 2 ways.
    first, using the super method as follows and pass in the arguments in interest.
    super.__init__()
    Second, call the parent's init method explicitly and pass in the arguments in interest.
    Employee.init(self, first, last, )
    5. Useful tools when exploring the inheritance system.
    .isinstance(instance, class)
    This method returns the boolean value of whether an instance belongs to a calss
    .issubclass(subclass, class)
    This method returns the boolean value of whether a class has inherited from the second class.
    6. Example of class inheritance
    Whisky library
    ++ when setting a default value for an ungiven argument, avoid using an empty mutable data type. That's a topic for another video.

  • @DigGil3
    @DigGil3 Před 7 lety +787

    Corey should be paid more.

  • @ShivamSingh-bx5lg
    @ShivamSingh-bx5lg Před 5 lety +416

    Print(isinstance(Corey,Super_humans))
    True

  • @MyTube4Utoo
    @MyTube4Utoo Před 6 lety +560

    One great thing about Corey's videos, you know it's safe to 'Like' them before you watch them! *lol*

    • @coreyms
      @coreyms  Před 6 lety +37

      Thanks!

    • @ashishm8413
      @ashishm8413 Před 6 lety +9

      I was about to make the same comment, then saw your post :)

    • @parthshah100
      @parthshah100 Před 6 lety +1

      What I was about to say

    • @arghoshj
      @arghoshj Před 6 lety +2

      Too True .. So Very True

    • @jqbscorner
      @jqbscorner Před 5 lety +2

      Escape the Matrix Beware, the youtube algorithm might not count these likes since they might be flagged for vote brigarding or bot voting.
      Afaik, you have to watch a minimum amount first before your votes are counted.

  • @rakeshkottu
    @rakeshkottu Před 5 lety +134

    I almost gave up on oop and then watched this series..The best playlist about oop.

    • @muhammadmuinmundzir9981
      @muhammadmuinmundzir9981 Před 4 lety

      We're on the same page here

    • @rajaspydey
      @rajaspydey Před 3 lety +1

      I just started learning and was looking for a good OOP tutorial, this one made them easy. I already kinda learnt Swift for few weeks and just realised that some of the concepts I was learning there was OOP and I just didn’t knew that it’s called OOP

    • @emreaka3965
      @emreaka3965 Před 3 lety

      Good teacher makes everything differernt. Before i get started to learn oop in python, i leaned oop in java and c# from a good teacher. Now, it is easier to learn oop in any other language because logic is behind of these language are same.

    • @mrhitsjr4775
      @mrhitsjr4775 Před 3 lety

      @@emreaka3965 who taught you java could you send the link pls

    • @emreaka3965
      @emreaka3965 Před 3 lety

      @@mrhitsjr4775 It is in my native language. You cannot understand his lessons.

  • @Jonathan-od5xc
    @Jonathan-od5xc Před 6 lety +221

    Your explanation and use of the terminology is flawless through these tutorials, and I can't begin to tell you how helpful that is!

    • @coreyms
      @coreyms  Před 6 lety +16

      Thanks! Glad to hear it's helpful

  • @rogut8
    @rogut8 Před 7 lety +231

    I have used Treehouse and currently I'm attending programming bootcamp, but only you can explain stuff so clearly. Once again - thanks a lot

  • @MarioIuliano
    @MarioIuliano Před 5 lety +28

    Studying data science at college and went through this topic in class and felt completely lost. Your tutorials made it click so easily and with no issues. Very well done Corey !

  • @xluyyjhfg
    @xluyyjhfg Před 4 lety +57

    2:45 - intro to Method resolution order and help() function
    6:06 - inheritance and super().__init__()
    10:50 - if attribute = None ... Else attribute
    16:00 - isinstance(self, ) and issubclass(, )
    17:36 - real world example

  • @calebmbugua7686
    @calebmbugua7686 Před 5 lety +58

    Thanks Mr corey!!!From Kenya and youre basically my role model in your humble approach towards sharing knowldge with us...In my own way ill try help as many people in my vicinity...tell them code is not as difficult..just as you are teaching us to love code!!! Thnaks Corey!!!

    • @coreyms
      @coreyms  Před 5 lety +12

      That’s great to hear!

  • @vinnyisntgud7221
    @vinnyisntgud7221 Před 4 lety +32

    this cheeky man trying to give himself a bigger raise then the other employees

  • @hatani
    @hatani Před 4 lety +6

    I have a confession - more and more videos I see from this playlist, the more I am in awe at how Corey manages to explain that often-missed 'WHY' along explaining the 'how'. The 'how' explanation is already brilliant, but that 'WHY' on the top... He just brute-forces it to click!

  • @kvnptl4400
    @kvnptl4400 Před 4 lety +28

    This Python OOP Tutorial playlist is super useful for everybody, hats off Corey Schafer, Subscribed and watching your other useful tutorials.

  • @vishwaskaupvijayananda3900
    @vishwaskaupvijayananda3900 Před 5 lety +56

    I've done my share of research before stumbling across this lecture series.
    Of all the Courses on Lynda, Udemy, and Coursera this is by far the best video tutorial I've come across.
    Thanks a lot Corey!

    • @vijendrachauhan3962
      @vijendrachauhan3962 Před 5 lety

      complete agree to you Vishwas, Corey presents the programming concepts in video so well that even complex topics are easy to understand. Keep up the good work Corey.

  • @richardfriedrichsen5339
    @richardfriedrichsen5339 Před rokem +2

    Honestly, the class tutorials are the best tutorials I have ever watched. You explain it in plain english, straight to the point and easy to understand. Thank you so much.

  • @manakupadhyay
    @manakupadhyay Před 4 lety +10

    If teaching is an Art, this guy is the Picasso of it.

  • @jwolf2759
    @jwolf2759 Před 8 lety +52

    Definitely one of the best explanations of inheritance I've seen. This whole series has been great... I've been writing scripts and small procedural programs for years, but have only recently started using classes and sub-classes. I wish this series had been around when I first started trying to learn about class years ago.

  • @PerfectSwingDance
    @PerfectSwingDance Před 4 lety +32

    If you're wondering and don't know why he didn't use default params like so: employees = [] (timing 11:24), you can consider the following scenario:
    Just create two managers without passing employee list in it. Add to one of them (via add_emp(self, emp)) new developer instance. Then print (print_emps) for both of them and you will see that one affects the other. This leads to unexpected behaviour. That's why he had to do so

    • @user-pk4cc1be8n
      @user-pk4cc1be8n Před 4 lety +1

      yes! but why? I am confused.

    • @pierreardouin6441
      @pierreardouin6441 Před 4 lety +7

      In python, when you state a=b it means you identify a to b and then they share the same id. It's not a big deal in general but when b is mutable (like a list or set) and you modify it (with append, add etc), then a is modified too. Same problem occurs when you duplicate with *, for example if you want a 4*5 2dim-list full of 0s, it's a bad idea to use [[0]*5]*4, cause it creates indeed what you expect but all rows are identified thus if you modify, say, the [2][3] element, then [0][3], [1][3] and [3][3] are modified too, which, usually, is not the expected behaviour.
      The proper definition for our list would be [[0]*5 for _ in range(4)].

    • @CorretorAlyssonGomes
      @CorretorAlyssonGomes Před 4 lety

      That being said, would this one be a good statement to substitute all the if...else structure at 11:25?
      self.employees = [] if not employees else employees

    • @lessknownislandarnode532
      @lessknownislandarnode532 Před 4 lety

      thank you. you are correct.

    • @00srinu
      @00srinu Před 4 lety +2

      @@user-pk4cc1be8n check the below video (@10:29) from Corey if you are still confused.
      czcams.com/video/zdJEYhA2AZQ/video.html

  • @himansuodedra2201
    @himansuodedra2201 Před 6 lety +33

    these explanations are beyond amazing. bought a course on udemy (best selling course to be specific) and what you have been able to explain to us in 6 videos has taken the course approximately 40 lectures!!!!

    • @thegreenroom5820
      @thegreenroom5820 Před 5 lety +3

      I did the same thing. The Udemy course is a bunch of useless code snippets. But You build things that are useful in the real world and help me be more creative.

    • @mainsequence1055
      @mainsequence1055 Před 5 lety +3

      That's deliberately done by Udemy so it feels like you're getting a lot of content. It's essentially bloat training. :D

  • @sebastianvbb
    @sebastianvbb Před 5 lety +7

    this is great, most people give such simple examples on youtube, that they undermine the purpose of having a class just to show you what you can do with it. That works if someone knows OOP very well, but for relatively new users its a mess. This is great stuff for me!

  • @SAJITAHAMED
    @SAJITAHAMED Před 6 lety +4

    Everyone will become programmer if all the teachers are like you. Awesome.

  • @zachgoll
    @zachgoll Před 7 lety +6

    I just can't get over how clear and concise your tutorials are. Saves all of us newbies hours of suffering :)

  • @parijatbandyopadhyay8057
    @parijatbandyopadhyay8057 Před 2 lety +1

    Corey, This is not at all a long video, it's simply a gem on Python inheritance

  • @flybyanuj
    @flybyanuj Před 7 lety +38

    I cannot even express how incredibly useful and precise your videos are. Thank you Corey!

  • @suryakiransuravarapu8081
    @suryakiransuravarapu8081 Před 2 lety +4

    Honestly, you are the one of the finest teachers I came across! I also see the humbleness in you, people like you make a world better place.

  • @fwesselhoft
    @fwesselhoft Před 6 lety +10

    Currently taking a python class at Hopkins university and getting a bit loss on the class subject; your videos are super helpful and make the subject much easier to understand. Thank you, great work!

    • @hemalpatel3770
      @hemalpatel3770 Před rokem

      Same when i learnt about oops. i was completely lost. This is the only instructor made me understand 😆

  • @timtech9361
    @timtech9361 Před 2 lety +1

    The explanation with the super__init__ method was flawless. 10/10

  • @jenmanzella1948
    @jenmanzella1948 Před 5 lety +8

    The pacing for these lessons is perfect and the content is fantastic. Thank you so much for making these!

  • @arpitanand4693
    @arpitanand4693 Před rokem +2

    My god, the level of clarity that you possess and are able to transfer forward is just unbelievable.
    Thank you so much for all your hard work!

  • @Keyandcartracking
    @Keyandcartracking Před 6 lety +3

    Corey... out of all the tutorials I have watched on Python. Yours are the best! You have a great ability to explain things in a way that is much easier to comprehend!

  • @marcuswest4572
    @marcuswest4572 Před 8 měsíci +1

    This is a benchmark for teaching, period.

  • @rajasekharreddy2410
    @rajasekharreddy2410 Před 6 lety +7

    Any body can upload the videos,but the way of your explanations Superb......No one never beat you Dear.....

  • @gokulsreekumar4371
    @gokulsreekumar4371 Před 6 lety +2

    You have done a great thing and even greater is the fact that you did not hide this stuff behind some "learning websites" , made it open to everyone in CZcams. Thanks a lot

  • @karthik-ex4dm
    @karthik-ex4dm Před 6 lety +7

    Python is just magical... Everything happens out of nothing
    I can visualize data structures such as linked lists etc from this lecture

  • @harrishandoko1558
    @harrishandoko1558 Před 5 lety +1

    I am a subscriber at Treehouse learning their Python course. I must admit, the instructor hasn't explained the dunder and inheritance syntax too well. But you did it flawlessly. Now it made so much more sense. Thank you.

  • @sugatakar7738
    @sugatakar7738 Před 5 lety +9

    Sir, you are undoubtedly one of the best Python tutors. Thanks so much for creating these awesome Python tutorials. :)

    • @hadimasri420
      @hadimasri420 Před 4 lety

      He is not one of the best, He IS the best

  • @kalyanreddy4579
    @kalyanreddy4579 Před 5 lety +1

    No comments...No words!!! Such a cool mentor..Not sure I can see anybody else like you!!! Hitting Bulls-eye in every video..straight to the point..and in depth concept...

  • @sumitchhabra2419
    @sumitchhabra2419 Před 4 lety +73

    Hey corey!
    I have bunch of courses from Udemy, Coursera, Bootcamp but nothing stands close to your explanation.
    Love from India

    • @sreejareddygummi4900
      @sreejareddygummi4900 Před 4 lety

      Pls share the link of Bootcamp to download coz I cant find it in PlayStore..

  • @jojosnumbers6868
    @jojosnumbers6868 Před 2 lety

    Just started to learn python from zero by myself and came accross classes not knowing what they actually are. These video-parts were the first one's recommmended upon searching on CZcams and scrolling through the comments I've noticed that seemingly I'm saving a lot of time by avoiding videos from other channels. Thank you, Corey!

  • @y.ulivee9015
    @y.ulivee9015 Před 7 lety +6

    I just love the way you explain things, I could listen for hours. This is a really great series!

  • @multiyumz
    @multiyumz Před 5 lety +1

    This is hands down the cleanest and most concise explanation of class inheritance I've ever seen. I was never sure what super did throughout my entire computer science degree (I'm stupid) but this cleared it up nicely in a 20min vid. Don't stay in school kids!

  • @itshowiedo
    @itshowiedo Před 6 lety +6

    May I just say "Superb!" on your explanation of Inheritances / Subclasses along with your excellent and useful examples!!

  • @jackfrost8412
    @jackfrost8412 Před 2 lety

    I have been using python for years now and I'm self taught. I have used Super().__init__() multiple times without fully understanding what it did. It was more of a copy/paste thing. I even tried searching the meaning but nothing really made sense. Now I understand what that does. Thank you so much. Thanks a lot for these videos.

  • @varunnagrare4912
    @varunnagrare4912 Před 3 lety +3

    All of Corey's videos are so good that I can feel a feeling of a bulb lighting up in my head. Like I achieved some enlightenment! In that case Corey is Buddha in Teaching. 😁

  • @snahnaichow835
    @snahnaichow835 Před 2 lety

    Dear Corey, great videos and I tell you why: You dont steal my time. You speak fast without ehhhhs and ahhhhs but not as fast as if you were on drugs like so many others. You describe the subject in a constant "explanation speed" so when I m concnetrated, I get it all from the first to the last minute.
    Then you dont waste my time while typing. Almost no errors. Prepared stuff. Great. So with your videos I get a lot of information fast and complete. I'll donate something for this. I watched many many learning videos over the last years and yours is one of the best. Simple, quick, condensed, to the point, no selfish nonsense.

  • @noemidavolio5532
    @noemidavolio5532 Před 5 lety +3

    As soon as I'm getting my informatics degree you'll be invited to my party man, hell, I should give you half my salary for the rest of my life. Thank you so much.

  • @alextorres9750
    @alextorres9750 Před rokem

    I am trying to avoid tutorials posted 2 and more years ago...but YOU ARE THE BEST...I got tired of chasing all those fresh tutorials an I am so grateful to find You. THANK YOU SO MUCH :)

  • @alyssanguyen1354
    @alyssanguyen1354 Před 7 lety +23

    bless your heart for making these videos

  • @chiragpalan9780
    @chiragpalan9780 Před 4 lety +3

    I wonder why there are 62 thumbs down!!!! this guy is just amazing.... Thanks a lot....

  • @sand9577
    @sand9577 Před 3 lety +4

    I'm a mechanical engineer, whose career died way before COVID dropped the last ton of dirt on top of its grave. I've been trying to re-skill my self into other industries of Mechanical Engineering, to learn some more process design stuff and migrate there; I like this Mechanical Engineering thing and I'm not about to give up. But those Mechanical Engineering courses are so incredible expensive, they are not meant for "outsiders" like me. Not only those courses are expensive, they are at times shallow and a sales pitch for: "tell your company to buy this other course where we go into greater detail. By the way, these other courses are on this other city so you can travel on company's dime and get paid to learn."
    It gets really expensive, and the instructor himself said the courses are not enough to break into that industry either way. The courses are meant to line the instructor pockets and pad the attendee resumes on their company.
    On the other hand, all the videos and resources I'm finding about coding, computer science and its kin; are not only FREE! they have depth, content and quality that I haven't seen in courses costing thousands of dollars in fancy Hotels.
    Corey Schafner, thank you so much for all of these Python courses. I'm beginning to entertain the idea of trying to migrate into coding or data science. I've always coded in ME and I have all the math either way.
    But...it's only a pipe dream. If I'm not able to get a job in ME after 2 years freelancing to scrape by, and having 8 years of experience as a Mechanical Engineer. I sincerely doubt anyone will accept an outsider into Information Technologies armed with youtube videos, Coursera certifications and zero years of coding.
    Once again, thank you for the work you put into these videos. And I really wish I could send something your way other than this self pitying rambling.

    • @rajaspydey
      @rajaspydey Před 3 lety

      Am 29 and have 8 years of experience in civil engineering, I didn’t liked coding in school and preferred CE over CS because my dads an construction contractor and no teacher actually taught me good. They were like include is something that all C programs should have and so you just memorise it. Never really taught about what’s binary and hexadecimals and taught us just how to do the conversion while it’s actually counting with 2 fingers and 6 fingers.
      After joining college I got an internet connection in home. Bought a mobile (Nokia N96)and tried to customise it. It all started there. My thirst for this. In fact python is the first code I used. Even though it wasn’t what I typed. I learnt swift for two weeks in lockdown. And kinda just like you bad marriage gave me anxiety, depression and other freebies that comes along with it. And COVID gave me the final blow. Am without job from Nov 2019 and still making my 60+ yo dad do business for me (small business so too much manual labor)
      After meeting psychiatrist I realised I should follow my passion. Eventhough I like CE I always wanted to make apps for construction industry which is still kinda old school and the existing ones are for big million dollar infra projects and doesn’t suit small businesses and our country. So with Excel & Apple Shortcuts app I made mini apps to suit my needs and it kinda worked. But the problem is adding more modules to it became time consuming because it wasn’t designed to do what I was doing.
      So I gave myself 6 months more to become an app and game developer.
      Now came here to learn python because of web scraping needs (for some background check to get rid of bad marriage) and I did it. So my first exposure to code is python and the first code I typed all by myself is python.
      We are in this together buddy. Keep learning on holidays and free time as side project. You will succeed.
      I have to take break because in work I don’t get time to do all these even on sundays.
      Am not sure what am talking now or what I said is appropriate. But keep in mind that you are not alone. Just don’t give up. And act fast I have been fiddling with basics of programming past few year and drop it, then start again. Instead just keep learning even if it’s a very slow pace. Just don’t give up.
      ALL THE BEST

  • @HaileeMiu
    @HaileeMiu Před 5 lety +1

    It is so great that you show real world examples, on top of your first examples be thought out and making sense.

  • @hiseggcelency
    @hiseggcelency Před 4 lety +3

    I'm so glad i've found your content! Finally i'm not getting distracted while listening! Your voice is calming and clear. Also somehow your explainations are interesting, and i find myself wanting to know more about the topic, which wasn't really the case with other tutiorials! Honestly i want to make tutorials too in the future, because i feel like when you teach, not one but actually two people are learning at that time. Repeatition is the key to becoming good in something, and when you repeat something while explaining it to someone, it becomes that much more effective. Keep up the good work!

  • @jeff_mci_gaming6018
    @jeff_mci_gaming6018 Před 6 lety +2

    So clear and precise...amazing video. I've see a lot of videos where people just run through projects with you and not really explaining the 'WHY' something is used or 'WHY'/'HOW' something happened, whether it be an error or a successfully executed line of code.....I think most tutorial videos focus too much on having people remember syntax... your videos are on-point. thanks a million.

  • @arunsaivemula1300
    @arunsaivemula1300 Před 8 lety +57

    u r really cool man ...! from my side i request u to make tutorial series on django package...thanq...in advance

    • @DracoWF
      @DracoWF Před 6 lety +1

      Django!

    • @appwebexperts5249
      @appwebexperts5249 Před 5 lety

      Django tutorials - czcams.com/channels/Jh4EQMRPQf9Vw0ifMmv7bg.html

  • @arminneashrafi2846
    @arminneashrafi2846 Před 5 lety +2

    The most Concise form of learning black magic, if I have ever seen it, this is super compact and usable, simply Perfect!

  • @mikegropp
    @mikegropp Před 6 lety +3

    Very well done! Appreciate your videos, Corey. Your choice of words and pace is perfect for my current understanding of Python.

  • @photon-9551
    @photon-9551 Před 5 měsíci

    Thanks Corey
    the best example and explanation of how to extend a sub-class's parameters that I have come across on the web.
    keep up the good work!

  • @bartagas2
    @bartagas2 Před 5 lety +3

    Wish I watched your OOP videos two years ago when you posted them! :P Great tutorials and good working examples to help follow along.

  • @jonspell88
    @jonspell88 Před 4 lety +1

    Best training on object oriented programming I've ever had. Seriously.

  • @artemiasalina1860
    @artemiasalina1860 Před 5 lety +4

    This is an outstanding series, Corey. Thank you.

  • @alper7313
    @alper7313 Před 3 lety +1

    Salute to this man. He just had to fire himself to create this tutorial 💯

  • @kinjomusic
    @kinjomusic Před 5 lety +3

    thank you again, so well explained . u are a gifted teacher Corey!

  • @giorgipatsatsia544
    @giorgipatsatsia544 Před 3 lety

    I'm just watching and clapping. Everything is so easy to understand. Just brilliant. Thank you Corey!!!!!!!!!

  • @lightninginmyhands4878
    @lightninginmyhands4878 Před 5 lety +9

    You just blew my mind with `help()`!!

  • @damiandamian7344
    @damiandamian7344 Před 8 měsíci

    I havent taken my comp sci class in about a year and its really nice to relearn the materials through these videos, thanks for all the help.

  • @flx4087
    @flx4087 Před 6 lety +3

    Thank you Corey, very helpful video.
    How would I build a from_string() alternative constructor (as shown in the Python OOP Tutorial 3) for the Developer class without having to rewrite the initial split (let's assume I need to do a little bite more complex stuff, for example dig trough a xml)?

  • @abladiti7953
    @abladiti7953 Před rokem

    I'm currently teaching myself python and when I'm on the other side I will have you to thank for developing a skill that is so in demand. Thank you Corey

  • @mohitdaga2356
    @mohitdaga2356 Před 5 lety +3

    I cannot thank you enough! You are amazing!
    Keep up the brilliant work! ^_^

  • @hasanbaaqeil42
    @hasanbaaqeil42 Před rokem

    I went through courses about different Classes in Python at Pluralsite and other four CZcamsrs but in vain... I could not understand it.. Your videos were perfect .. you explanations and examples are awsome .. clear organized simple and to the point... really really thank you

  • @cipcip4986
    @cipcip4986 Před 6 lety +3

    best python tutorials

  • @abduljelilali568
    @abduljelilali568 Před 2 lety

    I tried to understand OOP, and watched so many other videos, but this one, is by far the best resource I've ever came across. Hats off!!!!

  • @drewerving7428
    @drewerving7428 Před 6 lety +9

    Where have you been my whole life?

  • @Lux1431996
    @Lux1431996 Před 2 lety

    Your explanations here are more worth than bitcoin at their peak. Thank you so so much. This is extremely helpful!

  • @ankitbiradar8599
    @ankitbiradar8599 Před 7 lety +8

    Why do we need to implement super.__init__() in Developer.
    Developer already has these variables as it has inherited them from employee. What is the need for stating them explicitly again.

    • @BookOfSaints
      @BookOfSaints Před 7 lety

      I'd also like to know. I'm sure there is a reason, I am just curious! Thanks.

    • @danielschmidt7054
      @danielschmidt7054 Před 7 lety +21

      super() is needed if you want to add code to the inherited function. If you try his example without it, you completely overwrite Employee.__init__() and the other attributes (first, last, etc) are not available to Developer.

    • @ShovelShovel
      @ShovelShovel Před 7 lety +11

      its because when you define __init__() in Developer it overrode the __init__() method so it doesn't actually inherit the __init__() from Employee anymore and those variables are no longer defined for Developer. so in your __init__() method in Developer you need to call the __init__() from Employee using super() or Employee.__init__(self).

    • @pinochska
      @pinochska Před 6 lety

      Wow, truly great teacher

    • @3kelvinhong
      @3kelvinhong Před 6 lety +1

      I think it is because you want to add prog_lang argument to it but you can't just "add" up it, so you need to rewrite the (first, last, pay) and then now you can just add (prog_lang) to it.

  • @ayushyadav333
    @ayushyadav333 Před 2 lety +1

    Finally a good video with a good example rather than the print "parent class" and "subclass" XD

  • @rajatsharma2496
    @rajatsharma2496 Před 4 lety +8

    There is bug in line 27 28
    java developer has more Salary than python developer 😂..

  • @muralimanohar2130
    @muralimanohar2130 Před 4 lety +1

    3 years for this playlist
    But nothing can stand before this..
    Thank you corey sir..
    Love from india.

  • @j.rob.5943
    @j.rob.5943 Před 5 lety +3

    print(this_video.isGolden())
    >True

  • @waltz9230
    @waltz9230 Před rokem +1

    Thank you for actually explaining how and why things work rather than just saying "do this".

    • @lepidoptera9337
      @lepidoptera9337 Před rokem

      OOP doesn't work well. Did you ever try to develop a non-trivial piece of software? Did you notice how your data structures actually interact? Hint... it's NOT in isolated nodes. Oh, wait... why did I mention nodes just now? Would I, by any chance, be talking about trees and graphs? Think! ;-)

    • @waltz9230
      @waltz9230 Před rokem +1

      @@lepidoptera9337 What are you on about lol

    • @lepidoptera9337
      @lepidoptera9337 Před rokem

      @@waltz9230 I just told you that you are clueless. ;-)

    • @waltz9230
      @waltz9230 Před rokem +1

      @@lepidoptera9337 Go back to your retirement home grandpa. No one asked for your meaningless opinion.

  • @4upranit
    @4upranit Před 7 lety +3

    is super broken in python 2.7.xx?
    throws below error
    TypeError: super() argument 1 must be type, not instance

    • @mpagkalos93
      @mpagkalos93 Před 7 lety +2

      something has changed in python 3 regarding super().
      try this if you are using sublime :
      stackoverflow.com/questions/38963018/typeerror-super-takes-at-least-1-argument-0-given-error-is-specific-to-any

    • @holyproton8855
      @holyproton8855 Před 6 lety

      Yeah super() doesn't seem to work for 2.7, but using the parent class with self will work though

    • @creativedev2802
      @creativedev2802 Před 6 lety

      Employee.__İnit__(self,first,last,pay)
      self.prog_lang = prog_lang
      try this

  • @ss4yaasir524
    @ss4yaasir524 Před měsícem

    One of if not the best free python resources available even till today. I and so many others have learned so much from you man. Your content should be used to teach python at all universities lol. Thanks for all your amazing content man!

  • @admiralspyro9722
    @admiralspyro9722 Před 5 lety +19

    Developer earns 60000, Manager 90000, ... sad truth.

    • @denisds130
      @denisds130 Před 5 lety +4

      Why sad? Natural thing :D Higher responsibility = higher salary. Or higher value of the work = higher salary.

    • @MMABeijing
      @MMABeijing Před 5 lety +5

      @@denisds130 I actually thin that it is sad and unfair in many cases. Btw I don't think that a scrum manager has much responsability or pressure. It is as if we would say that it is normal for politicians to make 200k a year, because they have higher responsabilities and values, that's not corrent. Same with mainstream journalists: they are well paid activists, they bring no value and their sole responsability is to bs their viewers while looking really moral and deeply outraged. They are worthless .

    • @denisds130
      @denisds130 Před 5 lety +1

      @@MMABeijing No, they bring big value, which other people want pay for. If something is more desirable then it is better paid. Market rules. Politicians are not a part of the market - they are in government. Programmers are well paid because there is a big demand on their skills, which means that they have big value for employers.

    • @denisds130
      @denisds130 Před 5 lety +1

      @@MMABeijing It's unfair that somebody who do not work gets free money which we all have to give him in taxes. It's unfair when someone has no skills, no productivity and he want more money because he "deserves" it. No. If you won't work for it, you will not have it. That is fair.

    • @MMABeijing
      @MMABeijing Před 5 lety +2

      @@denisds130 I would say that everybody , including lawyers/politicians/mainstream journalists are part of the market as a rational actor would/could decide to opt for those professions. My experience in IT (in telecommunications) had me witness very skilled programmers stuck in engineering work where there was little chance of promotions while a few people who could not make it in their technical work opted for working as project managers because it was in fact the easy way up. This was a major reason why there was a major and growing dissatisfaction within the R&D teams within *okia's team that I interviewed. At the same time that situation was dealt totally differently within Huawei where team managers and project managers had to have made their arms and proven excellent before they were put in a position of management. In that respect Huawei was doing a better job at dealing with a situation that was unfair from the perspective of the engineers interested in research and who wanted to work within a company where research and researchers would be the hear and sould of the organisation. I see your point, hopefully this longer post lets you see my original point better.

  • @sanidhyas3s
    @sanidhyas3s Před 2 lety

    The use of help( ) makes it so much more into the face, I love it!

  • @ayushgupta7731
    @ayushgupta7731 Před 7 lety +3

    Hi Corey. Thanks for the video.
    I didn't get the below part:
    class Managers(Employee):
    def __init__(self,first,last,pay,employees=None):
    Employee.__init__(self,first,last,pay)
    self.employees=employees
    Here you are instantiating as:
    mgr1=Manager(' Sue','Smith',90000,[dev1])
    But 'dev1' is an object(dev1=Developer('Corey','Schafer',50000,'Python') not a single entity(value). What values are getting passed in the list to 'mgr1'.
    Also after doing the same things, I am not able to print the employees using:
    def print_emps(self): method.
    I am getting:[] whenever I am trying to print.
    PS: I AM USING PYTHON 2.7.12.
    Thanks for the help.

    • @sdram111
      @sdram111 Před 7 lety

      Hi Corey, am also having this doubt. Could you please answer to this question.

    • @amitbisht6972
      @amitbisht6972 Před 7 lety +3

      [Ayush Gupta]
      dev1 = Developer('Corey','Schafer',50000,'Python')
      the above line creates the object of Developer class or instantiate the Developer class and you can pass the objects as list it, carries all the info with it.
      and about print_emps() i think you are just printing emp which corresponds to the object of developer class, you must do emp.fullname() which will call fullname method and is equivalent to dev1.fullname() or dev2.fullname() if it is there
      I hope this helps you understand .

    • @Sikkandarsulaiman
      @Sikkandarsulaiman Před 7 lety

      First I'll clarify about your print_emps(self)
      Sure you would have the statement
      -----------
      for emp in self.employees:
      print emp
      -----------
      inside your print_emps(self)
      You're getting this because you're printing the object itself, it leads to print the address of particular instance and not all its corresponding attributes. Thats the reason Corey mentioned to print the full name.
      Then, for a Python list, it can store an object. Of course objects are single entities. But remember its an instance, rather than an entity thats why you should print values associated with the instances and not the instances itself

    • @gautamj7450
      @gautamj7450 Před 6 lety

      It's best to switch over to Python 3.6 ASAP! ;-)

    • @aishaverheecke7845
      @aishaverheecke7845 Před 6 lety

      You should use the __str__ function, it returns a string from your function instead of the instance

  • @mustafizahmed1317
    @mustafizahmed1317 Před 2 lety

    I came to watch this from a popular learning platform to understand python inheritance better. Thank you!

  • @joelloyd2633
    @joelloyd2633 Před 3 lety

    I feel the beginnings of a question formulating in my mind and then....BAM! Corey answers it before I even knew what I wanted to ask.

  • @susannaventafridda430
    @susannaventafridda430 Před 6 lety

    If you're using Python 2.x try writing the following at the very beginning of your code (found on stackoverflow and really helped me as I was stuck with error messages): __metaclass__ = type
    In addition, "super" for the Developer class becomes: super(Developer,self).__init__(first, last, pay)
    and for the Manager class: super(Manager,self).__init__(first, last, pay)
    Finally I removed the arrow as it was problematic because Python considered it as an object (error: 'str' object has no attribute 'emp')
    Now it all works!

  • @stanc846
    @stanc846 Před 6 lety +2

    Thank you for sharing how isintance() and issubclass() are used to get a good insight of understanding how the classes are being used in a given program. I can use this in decomposing my own code as well as others.

  • @hadimasri420
    @hadimasri420 Před 4 lety +1

    Man, how can I say thank you so much in a different way... there are no words that can describe how awesome you are, I know this is common for you, but if you feel what I'm feeling right now you would have been (NO WORD TO DESCRIBE...).
    The awesome thing about you is that whenever I get bored of programming, I immediately watch a video of yours, then I recover my mental health.
    Please make new videos with new topics about Python and Python OOP. we need to master them with your help.

    • @coreyms
      @coreyms  Před 4 lety +1

      Thanks! I really appreciate that

  • @MohammedAhmed-wq2jf
    @MohammedAhmed-wq2jf Před 6 lety +1

    Corey, your videos are a delight for gaining clear understanding on python. Even Few of Udemy videos fail to deliver the way you have done. Thank you

  • @Colstonewall
    @Colstonewall Před 8 lety

    I've gone over countless Python (and other) tutorials, and you're definitely the best teacher or at least in the top 2. This (video) is nothing new to me, but sometimes I go back and watch tuts just for a refresher or to see if I like the teacher. You make it easy to grasp, and in an exciting way.
    I hope you continue making tutorials, Corey, cause you're so damn good at it. Thanx again.

  • @jerrywang3225
    @jerrywang3225 Před 6 lety +2

    hi, you are so far the greatest Python teacher on CZcams who can clearly explain the class inheritance concept, the examples couldn't be better. Thanks so much/

  • @dustinhxc
    @dustinhxc Před rokem

    Wow the explanation of how Inheritance will be helpful in the end of the video was wonderful, my eyes are now open!

  • @umanagaswamy1180
    @umanagaswamy1180 Před 8 lety +2

    Corey, this is one of the best tutorials I have seen on inheritance! Thanks so much for a concise explanation. I have been developing OOP for a few years now and I learned a ton of stuff watching your videos. For using super in python 2.7, I had to modify the code a little bit as follows:
    class Employee(object):
    ...
    class Manager(Employee):
    raise_amount = 1.10
    def __init__(self, first, last, pay, employees=None):
    super(self.__class__, self).__init__(first, last, pay) #

    • @christianniyokwizerwa
      @christianniyokwizerwa Před 2 lety

      Thank you for sharing @Uma Nagaswamy. Your comment is still relevant 5 years later!

  • @mohammednagdy6661
    @mohammednagdy6661 Před 6 lety +2

    First time I understand why we use classes. You're the best!

  • @chanteld2954
    @chanteld2954 Před 2 lety

    I cannot express to you how helpful your videos have been. I have watched all my uni lectures and read so many articles explaining what classes are, but only your set of videos have gotten me to grasp the concept completely

  • @rockelleg.3406
    @rockelleg.3406 Před 9 měsíci

    thank you so much for this video! I have been struggling through my Python Class; you are a God send!

  • @Jtmxm
    @Jtmxm Před 7 lety

    Corey, your lectures about class are really wonderful and clear to understand for beginners !!! I never find anyone else who talks about the class that clear.

    • @Jtmxm
      @Jtmxm Před 7 lety

      In addition, would you please recommend me some tutorials concerning how python can treat large volume of data more quickly, for example, how we can run the codes on a serveur, distributed computing or how to use python with hadoop or map reduce. Thanks !

  • @rezwanzakaria1754
    @rezwanzakaria1754 Před 4 lety

    Dude I'm taking python on Coursera made by Google IT. Couldn't understand few things ... so came here and you made it clear as crystal. Why waste money when you got a Super human like Corey