Python OOP Tutorial 4: Inheritance - Creating Subclasses

Поделиться
HTML-код
  • Опубликовано: 22 май 2024
  • In this Python Object-Oriented Tutorial, we will be learning about inheritance and how to create subclasses. Inheritance allows us to inherit attributes and methods from a parent class. This is useful because we can create subclasses and get all of the functionality of our parents class, and have the ability to overwrite or add completely new functionality without affecting the parents class in any ways. Let's get started.
    Python OOP 1 - Classes and Instances - • Python OOP Tutorial 1:...
    Python OOP 2 - Class Variables - • Python OOP Tutorial 2:...
    Python OOP 3 - Classmethods and Staticmethods - • Python OOP Tutorial 3:...
    Python OOP 4 - Inheritance - • Python OOP Tutorial 4:...
    Python OOP 5 - Special (Magic/Dunder) Methods - • Python OOP Tutorial 5:...
    Python OOP 6 - Property Decorators - • Python OOP Tutorial 6:...
    The code from this video can be found at:
    github.com/CoreyMSchafer/code...
    ✅ Support My Channel Through Patreon:
    / coreyms
    ✅ Become a Channel Member:
    / @coreyms
    ✅ One-Time Contribution Through PayPal:
    goo.gl/649HFY
    ✅ Cryptocurrency Donations:
    Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
    Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
    Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
    ✅ Corey's Public Amazon Wishlist
    a.co/inIyro1
    ✅ Equipment I Use and Books I Recommend:
    www.amazon.com/shop/coreyschafer
    ▶️ You Can Find Me On:
    My Website - coreyms.com/
    My Second Channel - / coreymschafer
    Facebook - / coreymschafer
    Twitter - / coreymschafer
    Instagram - / coreymschafer
    #Python

Комментарии • 1,2 тыс.

  • @DigGil3
    @DigGil3 6 лет назад +772

    Corey should be paid more.

  • @user-xc5xf8gp8n
    @user-xc5xf8gp8n 4 года назад +758

    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.

  • @ShivamSingh-bx5lg
    @ShivamSingh-bx5lg 5 лет назад +401

    Print(isinstance(Corey,Super_humans))
    True

    • @JacobScott0000
      @JacobScott0000 4 года назад

      😂

    • @terence7592
      @terence7592 4 года назад +28

      syntax error

    • @aadilrashidnajar9468
      @aadilrashidnajar9468 4 года назад +14

      @@terence7592 print(isinstance(Corey, SuperHumans))
      >>> True

    • @RecursiveTriforce
      @RecursiveTriforce 3 года назад +7

      @@aadilrashidnajar9468
      That's still wrong.
      >>> input
      output

    • @g__shan
      @g__shan 3 года назад

      @@RecursiveTriforce 🤣🤣🤣🤣😂

  • @scorpp149
    @scorpp149 7 лет назад +905

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

    • @josecruz2574
      @josecruz2574 4 года назад +12

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

  • @MyTube4Utoo
    @MyTube4Utoo 6 лет назад +548

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

    • @coreyms
      @coreyms  6 лет назад +36

      Thanks!

    • @ashishm8413
      @ashishm8413 6 лет назад +9

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

    • @parthshah100
      @parthshah100 6 лет назад +1

      What I was about to say

    • @arghoshj
      @arghoshj 5 лет назад +2

      Too True .. So Very True

    • @jqbscorner
      @jqbscorner 5 лет назад +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.

  • @vinnyisntgud7221
    @vinnyisntgud7221 4 года назад +31

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

  • @rakeshkottu
    @rakeshkottu 4 года назад +129

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

    • @muhammadmuinmundzir9981
      @muhammadmuinmundzir9981 4 года назад

      We're on the same page here

    • @rajaspydey
      @rajaspydey 3 года назад

      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 3 года назад

      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 2 года назад

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

    • @emreaka3965
      @emreaka3965 2 года назад

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

  • @Jonathan-od5xc
    @Jonathan-od5xc 6 лет назад +217

    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  6 лет назад +16

      Thanks! Glad to hear it's helpful

  • @Aaronisification
    @Aaronisification 3 года назад +56

    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

  • @manakupadhyay
    @manakupadhyay 4 года назад +10

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

  • @rogut8
    @rogut8 7 лет назад +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

    • @jeff_mci_gaming6018
      @jeff_mci_gaming6018 6 лет назад +2

      I concur with everything you and Lukaz R stated...

    • @Cloud-577
      @Cloud-577 3 года назад +4

      Hey there I'm from Treehouse too!

  • @MarioIuliano
    @MarioIuliano 4 года назад +27

    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 !

  • @calebmbugua7686
    @calebmbugua7686 5 лет назад +57

    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  5 лет назад +11

      That’s great to hear!

  • @hatani
    @hatani 4 года назад +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!

  • @flybyanuj
    @flybyanuj 6 лет назад +38

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

  • @jwolf2759
    @jwolf2759 7 лет назад +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.

  • @kvnptl4400
    @kvnptl4400 4 года назад +28

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

  • @jenmanzella1948
    @jenmanzella1948 5 лет назад +8

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

  • @Keyandcartracking
    @Keyandcartracking 6 лет назад +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!

  • @vishwaskaupvijayananda3900
    @vishwaskaupvijayananda3900 5 лет назад +54

    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 5 лет назад

      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.

  • @y.ulivee9015
    @y.ulivee9015 6 лет назад +6

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

  • @zachgoll
    @zachgoll 6 лет назад +6

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

  • @chiragpalan9780
    @chiragpalan9780 4 года назад +3

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

  • @alyssanguyen1354
    @alyssanguyen1354 7 лет назад +23

    bless your heart for making these videos

  • @sebastianvbb
    @sebastianvbb 4 года назад +6

    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!

  • @itshowiedo
    @itshowiedo 6 лет назад +6

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

  • @chanteld2954
    @chanteld2954 2 года назад

    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

  • @mustafizahmed1317
    @mustafizahmed1317 2 года назад

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

  • @SAJITAHAMED
    @SAJITAHAMED 6 лет назад +3

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

  • @suryakiransuravarapu8081
    @suryakiransuravarapu8081 Год назад +3

    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.

  • @jerrywang3225
    @jerrywang3225 6 лет назад +2

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

  • @Colstonewall
    @Colstonewall 7 лет назад

    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.

  • @mikegropp
    @mikegropp 5 лет назад +3

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

  • @artemiasalina1860
    @artemiasalina1860 5 лет назад +4

    This is an outstanding series, Corey. Thank you.

  • @richardfriedrichsen5339
    @richardfriedrichsen5339 Год назад +1

    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.

  • @snahnaichow835
    @snahnaichow835 2 года назад

    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.

  • @hiseggcelency
    @hiseggcelency 4 года назад +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!

  • @rajasekharreddy2410
    @rajasekharreddy2410 6 лет назад +6

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

  • @arminneashrafi2846
    @arminneashrafi2846 5 лет назад +2

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

  • @gokulsreekumar4371
    @gokulsreekumar4371 5 лет назад +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 RUclips. Thanks a lot

  • @sumitchhabra2419
    @sumitchhabra2419 4 года назад +72

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

    • @sreejareddygummi4900
      @sreejareddygummi4900 4 года назад

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

  • @bartagas2
    @bartagas2 5 лет назад +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.

  • @HaileeMiu
    @HaileeMiu 5 лет назад +1

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

  • @abduljelilali568
    @abduljelilali568 Год назад

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

  • @kinjomusic
    @kinjomusic 5 лет назад +3

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

  • @PerfectSwingDance
    @PerfectSwingDance 4 года назад +31

    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 4 года назад +1

      yes! but why? I am confused.

    • @pierreardouin6441
      @pierreardouin6441 4 года назад +6

      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 4 года назад

      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 4 года назад

      thank you. you are correct.

    • @00srinu
      @00srinu 3 года назад +2

      @@user-pk4cc1be8n check the below video (@10:29) from Corey if you are still confused.
      ruclips.net/video/zdJEYhA2AZQ/видео.html

  • @arpitanand4693
    @arpitanand4693 Год назад +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!

  • @sanidhyas3s
    @sanidhyas3s Год назад

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

  • @sugatakar7738
    @sugatakar7738 5 лет назад +9

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

    • @hadimasri420
      @hadimasri420 4 года назад

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

  • @karthik-ex4dm
    @karthik-ex4dm 5 лет назад +6

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

  • @giorgipatsatsia544
    @giorgipatsatsia544 3 года назад

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

  • @bradyminer6471
    @bradyminer6471 3 года назад

    What I have been struggling to understand over the past few weeks you solved in one hour. Thank you so much!

  • @himansuodedra2201
    @himansuodedra2201 6 лет назад +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 5 лет назад +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 5 лет назад +3

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

  • @varunnagrare4912
    @varunnagrare4912 2 года назад +2

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

  • @jonspell88
    @jonspell88 3 года назад +1

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

  • @huntermaverick5114
    @huntermaverick5114 5 лет назад +2

    You have a really suitable voice for this and the way you explain everything is just amazing Corey. The other short video tutorials on RUclips only have about 5 min each, that's depressing. You are the best at this!

  • @fwesselhoft
    @fwesselhoft 6 лет назад +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 10 месяцев назад

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

  • @mohitdaga2356
    @mohitdaga2356 5 лет назад +3

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

  • @saifahmad141
    @saifahmad141 Год назад

    please never hesitate to make long videos . videos like these are pure gold. awesome explanation thank you Corey

  • @keevee09
    @keevee09 7 лет назад

    These video tutorials take me back to my days in lectures, learning about ADT's in Java. You provide a very clear and concise presentation at a good speed, broken into logical, digestible bites. Excellent work!

  • @cipcip4986
    @cipcip4986 6 лет назад +3

    best python tutorials

  • @sand9577
    @sand9577 3 года назад +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 3 года назад

      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

  • @sayan2784
    @sayan2784 4 года назад +1

    I keep coming back to your tutorial again and again... you are the best!

  • @arunsaivemula1300
    @arunsaivemula1300 7 лет назад +57

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

    • @DracoWF
      @DracoWF 6 лет назад +1

      Django!

    • @appwebexperts5249
      @appwebexperts5249 5 лет назад

      Django tutorials - ruclips.net/channel/UCJh4EQMRPQf9Vw0ifMmv7bg

  • @lightninginmyhands4878
    @lightninginmyhands4878 5 лет назад +9

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

  • @MohammedAhmed-wq2jf
    @MohammedAhmed-wq2jf 5 лет назад +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

  • @BradMeanswrgi
    @BradMeanswrgi 4 года назад +2

    Holy shit, I've been needing help on explaining the syntax for Classes for over a week now and these videos are GOLD. I think I set a personal record on fastest Subscribed click.

  • @flx4087
    @flx4087 5 лет назад +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)?

  • @drewerving7428
    @drewerving7428 6 лет назад +9

    Where have you been my whole life?

  • @mohammednagdy6661
    @mohammednagdy6661 5 лет назад +2

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

  • @jojosnumbers6868
    @jojosnumbers6868 2 года назад

    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 RUclips 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!

  • @rajatsharma2496
    @rajatsharma2496 4 года назад +8

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

  • @ankitbiradar8599
    @ankitbiradar8599 7 лет назад +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 7 лет назад

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

    • @danielschmidt7054
      @danielschmidt7054 7 лет назад +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 6 лет назад +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 6 лет назад

      Wow, truly great teacher

    • @3kelvinhong
      @3kelvinhong 6 лет назад +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.

  • @damiandamian7344
    @damiandamian7344 4 месяца назад

    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.

  • @alextorres9750
    @alextorres9750 Год назад

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

  • @4upranit
    @4upranit 7 лет назад +3

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

    • @mpagkalos93
      @mpagkalos93 6 лет назад +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 6 лет назад

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

    • @creativedev2802
      @creativedev2802 6 лет назад

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

  • @j.rob.5943
    @j.rob.5943 4 года назад +3

    print(this_video.isGolden())
    >True

  • @muralimanohar2130
    @muralimanohar2130 4 года назад +1

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

  • @harrishandoko1558
    @harrishandoko1558 5 лет назад +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.

  • @ayushgupta7731
    @ayushgupta7731 7 лет назад +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 7 лет назад

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

    • @amitbisht6972
      @amitbisht6972 7 лет назад +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 6 лет назад

      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 6 лет назад

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

    • @aishaverheecke7845
      @aishaverheecke7845 5 лет назад

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

  • @admiralspyro9722
    @admiralspyro9722 5 лет назад +19

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

    • @denisds130
      @denisds130 5 лет назад +4

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

    • @MMABeijing
      @MMABeijing 5 лет назад +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 5 лет назад +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 5 лет назад +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 5 лет назад +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.

  • @timtech9361
    @timtech9361 2 года назад

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

  • @jeff_mci_gaming6018
    @jeff_mci_gaming6018 6 лет назад +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.

  • @OnlineMediaCollection
    @OnlineMediaCollection 5 лет назад +1

    Your teaching skill is beyond others! Great job!!!

  • @zaha7a752
    @zaha7a752 4 года назад +1

    Corey Schafer you are a god in explaining Python OOP. Love these videos. Good job!

  • @photon-9551
    @photon-9551 Месяц назад

    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!

  • @multiyumz
    @multiyumz 5 лет назад +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!

  • @jf_8311
    @jf_8311 Год назад

    Clear and concise explanations, i can't ask for more! Thank you!!!

  • @karennascimento6544
    @karennascimento6544 7 лет назад

    Excellent series of videos covering classes, what they are for and how to use them. Very comprehensive in the way you build up from simple to more complex topics.

  • @altunbikubra
    @altunbikubra 3 года назад +1

    Very explanatory examples nicely put. Whenever I get confused about a topic, or I want to learn something I find myself in your channel. And you are never a disappointment :)

  • @NickSlaughterDude
    @NickSlaughterDude 5 лет назад +1

    Phenomenal tutorial indeed. Well thought examples explained in clear and detailed manner. Thank you so much Corey.

  • @strykerace
    @strykerace 5 лет назад +2

    thank you so much. I was having an unbelievably hard time with the function of super() and your video finally solidified the why I would want and need it and how it reinforces inheritance and i how i could accidentally "opt out" of inheritance if i didn't use it when i needed to.

  • @myusername6595
    @myusername6595 5 лет назад +2

    definitely the best intro to OOP in general that i've found

  • @karimsid
    @karimsid 5 лет назад +1

    excellent explanation with one example through out. I have been reading about the classes this video is one thorough answer to most of the questions I had. Corey is genius

  • @WIZURAI-AGV
    @WIZURAI-AGV 5 лет назад +1

    explaining Python very clear, I think he is the best mentor in explaining Python. *thumbs up!

  • @stanc846
    @stanc846 6 лет назад +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.

  • @marcuswest4572
    @marcuswest4572 4 месяца назад

    This is a benchmark for teaching, period.

  • @simaphore
    @simaphore 7 лет назад +1

    I had been trying to get this concept all day until I found this video and it answered all my questions! thank you!

  • @kalyanreddy4579
    @kalyanreddy4579 4 года назад +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...

  • @JazzyJunior
    @JazzyJunior 4 года назад +1

    This is such a fantastic set of instructions. Thank you, cleared up so many concepts!