Python OOP Tutorial 5: Special (Magic/Dunder) Methods

Sdílet
Vložit
  • čas přidán 22. 07. 2024
  • In this Python Object-Oriented Tutorial, we will be learning about special methods. These are also called magic or dunder methods. These methods allow us to emulate built-in types or implement operator overloading. These can be extremely powerful if used correctly. We will start by writing a few special methods of our own and then look at how some of them are used in the Standard Library. Let's get started.
    Python Docs: docs.python.org/3/reference/d...
    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

Komentáře • 527

  • @kickbuttowsk2i
    @kickbuttowsk2i Před 4 lety +539

    the amount of 'aha' moment in this series is unimaginable.

    • @plato5138
      @plato5138 Před 3 lety

      @Tomas Alvaro Stop with those spam comments

    • @sndselecta
      @sndselecta Před 3 lety

      Hilarious.

    • @MTSNSri
      @MTSNSri Před 2 lety

      @@sndselecta
      L

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

      Sorry to be off topic but does any of you know of a tool to log back into an Instagram account?
      I stupidly lost the password. I love any tips you can give me

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

      @Timothy Wyatt instablaster =)

  • @ryanthornton3556
    @ryanthornton3556 Před rokem +42

    6 years later and this is still invaluable

  • @garydunken7934
    @garydunken7934 Před 7 lety +765

    What I like about your videos is that there's no emming, erring or dribbling of words. Well planned and execution of tutorial; nice clear, crisp flow and sticking to point really well. Excellent. Please keep them coming.

    • @effuseakay
      @effuseakay Před 5 lety +15

      I agree. I can see you put a lot of work into planning your videos. There is barely any typos, everything is crystal clear with examples, etc. Seriously thank you so much!

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

      @@effuseakay do you think he is cutting his videos and looking up what to say next? It seems like he does everything out of memory spontaneously, but perfectly fine

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

      That's why Corey puts a video per month or so, buuut they are so good.

    • @ildar_eto_ya
      @ildar_eto_ya Před 4 lety

      Aaaaaahhhyeeeeeeeaaahhhhh!

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

      Just like CS50. PLAIN & SIMPLE

  • @andresvodopivec5950
    @andresvodopivec5950 Před 5 lety +340

    Normally I never comment but really have to say tow things: thanks so much for the tutorial and by far the best and flawless (material and speech) python tutorial ever seen. Nice talent Corey!

  • @christianfuchs9405
    @christianfuchs9405 Před 6 lety +69

    best python tutorials on youtube. period.

  • @betulabendula6270
    @betulabendula6270 Před 7 lety +56

    These OOP tutorials are worth gold! They make difficult subject to look so easy!

  • @Mrjarnould
    @Mrjarnould Před 8 lety +95

    Keep up the Python OOP tutorial, they're great!

  • @nelsongg347
    @nelsongg347 Před 5 lety +40

    I started with Python from two weeks ago I come from Php and Java so I have a good understanding of Classes and Objects, but I have to tell you that the way you present every topic is magistral. Thank you very much for your flawless tutorial. And the extra for me is that your tutorials are also an English class.

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

    My favorite part of your tutorials is that you give a great great example come from standard or well-known library to show us what those skills are used in dealing with real-world programming issues. A hundred thumb-ups!

  • @ankurjain5286
    @ankurjain5286 Před 8 lety +79

    @Corey - You are an excellent teacher and know exactly how to tell/teach about any topic. I have seen all of your videos and learnt a lot by watching these tutorials. Can you please upload some videos on some of the python concepts like - Multiprocessing, Design patterns, MetaClasses as well.

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

    So clear, concise, and precise. Best Python tutorials I have yet come across on CZcams

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

    Great series of tutorials on OOP! I really love them. Very clear and with a speedy pace!

  • @navroze92
    @navroze92 Před 5 lety +6

    You Sir need a million subs just for teaching this one episode. So clean and precise!! Thank you for the work you put in we really appreciate it.

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

    These videos are such a lifesaver for me. Gives me actual understanding instead of me just stumbling along, not knowing what I'm really doing.

  • @calistosmindfulsoundsofnature

    This video specifically has opened some doors for me in understanding classes and special methods used inside algorithms. Always learning something new each day on my coding journey!!! It never stops and I love it!!

  • @Caffeinegoesinface
    @Caffeinegoesinface Před 7 lety +13

    you kick ass! This has been invaluable to a university project I'm working on at the moment
    Thanks!

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

    This was a great video. I've been curious about operator overrides in python for a little bit. Blundered into the answers in this video and within 30 minutes had a working Vector class from scratch that handles all the basics. Thanks much for the really excellent content on your channel. I have to echo the other folks who point out how well you present the information. Well done!

  • @sueholder703
    @sueholder703 Před 4 lety +26

    I have just spent the day going through this series as I am studying and needed to understand this concept better. Your series has been superb and I'm so thankful. Thank you for sharing your extensive knowledge in a way that is clear and easy to understand. When I am working I will support through Patreon to pay it forward so you keep on making them. I am going to watch many more of your videos from here on, I am sure.

  • @baterickpatman
    @baterickpatman Před rokem +1

    DUDE you're the fkn MAN.. been following this series and everything about your presentation is SO great. Thank you so much :) I will be donating

  • @CharlesDibsdale
    @CharlesDibsdale Před 7 lety +1

    Corey, thanks for your tutorials, you are clear to the point, and avoid waffle. The dunder methods are helping me debug my app much more efficiently.

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

    Your tutorials take into depth, which is something others of same kind never did. I'm lucky finding you.

  • @artmcclure637
    @artmcclure637 Před 7 lety +9

    Finally, I understand Classes. Thank you!

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

    Ive been watching your videos and they have already helped me in my Job as a Site Reliability Engineer to write better python code, you have also helped me understand concepts that I haven't truly understood for the years Ive been in software development. Thank you for your great explanations. You definitely are making a great difference in peoples lives. Keep on Keeping on!

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

    Boy am I glad I found this tutorial. II was over my head on OOP. Can't believe how much I've learned in just 5 videos. Right on Corey!!

  • @L0V3V4MP1R3
    @L0V3V4MP1R3 Před 4 lety +17

    I had an ungodly amount of trouble understanding OOP in general and I think that in the middle of many other tutorials, yours were the first that I could finally understand and keep up with without getting lost halfway through the lecture.
    Thank you so much, keep the wonderful content coming! ♥

  • @KnightShade227
    @KnightShade227 Před 4 lety

    been playing around with code trying to learn and I've just watched the four previous videos on classes, they're the one thing I've had issues with during my year of coding so far, and your videos helped me figure out how to incorporate them into my lil pygame, so thanks! good job breaking them down and explaining each part of them! I'll finish this one tomorrow morning 😁

  • @user-qu2zc4rp9v
    @user-qu2zc4rp9v Před 6 lety +1

    Questions are sophisticated but your answers are simple. Great respect and hundreds years of happiness!

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

    Who is down voting your videos? You are a master and clearly demonstrate your command of this language by how easily you simplify these concepts for me. Thank you, good sir!

  • @mrmabb123
    @mrmabb123 Před 5 lety +17

    I finally feel I have a complete picture on Python basics despite already learning it for 4 months. Thanks.

  • @JeremyFisher
    @JeremyFisher Před 4 lety

    You don't know how much we appreciate your work here Corey, best way of teaching and a good soul, we love you.

  • @user-mj1lu4cl1j
    @user-mj1lu4cl1j Před rokem

    If I ever had a any doubts on python I would look no further than your playlist. I recommend people to refer your videos first because it's no time-wasting around and just pure content.. Plus hat's off to your clear and concise language with in depth knowledge and a perfect pace while explaining.. Keep up the great work.. You are flamboyant God bless you Corey.. :)

  • @GodsNode
    @GodsNode Před 6 lety +19

    You are like the Khan Academy of Python code. Great explanations and examples.

  • @tanmayag97
    @tanmayag97 Před 4 lety +4

    Probably the best tutorial of OOPS in the world. 👌

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

    No explanation can be better than what you did during the whole playlist. Thanks.

  • @Asparuh.Emilov
    @Asparuh.Emilov Před rokem +3

    You are by far, the most absolute best Python Teacher out there! Thank you soooooo much for being the best! ♥️♥️♥️♥️♥️

  • @dustinhxc
    @dustinhxc Před rokem

    Wow changing what it displays is priceless. Thank you for the Dunder explanation!

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

    I love your videos man, seriously I don't get it why in college they don't explain it like you do- I just understood a lot about Python thanks to you.
    I'm dead serious I was frustrated I didn't got it right, thank you very much for sharing your knowledge !

  • @dozieu8539
    @dozieu8539 Před 3 lety

    Communication is so human and yet so otherworldy, thanks Corey

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

    I am an avid follower of your tutorials from the day CZcams recommend me your ___name___ video. I loved it and got hooked to your style of teaching.
    Today when I got stuck at a problem in Hackerrank, I *Coreyed* the problem (fancy term for Googled when it comes to Python) and voila there it is; the video I wanted!
    Viel Danke Corey!

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

    One of the best python tutorials I’ve ever seen

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

    Exceptionally well, such organized Tutorials are intellectual assets that are really devoted free to learner community.

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

    First, I must say huge thanks ) I'm so impressed by your videos and have been learning through them, and I watch your channel pretty much every day.

  • @gershondevadason4656
    @gershondevadason4656 Před 2 lety

    Exactly what I needed. Clear, comprehensive and great examples! Nice work man!

  • @atulpanthri4729
    @atulpanthri4729 Před 3 lety

    You have very deep understanding of python, teaching and choosing examples. Its really hard to understand where general student fail and get frustrated and you know this all. Thanks a lot Sir

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

    Thank you for this awesome set of tutorials. I came in from the PHP world and your explanations gave me a headsup to Python OOP

  • @antonkamnev2067
    @antonkamnev2067 Před 3 měsíci +2

    My eyes have finally opened to so many things in python! Thanks!

  • @DShawnPaytonOffiicial
    @DShawnPaytonOffiicial Před rokem +1

    I just want to say, your videos are excellent. You provide a clear explaination of everything. Thank you.
    I was having issues with __repr__ and __str__ until I realized that I was putting them in the wrong class. Hopefully this will help anyone else having similar issues.

  • @23TrevorE
    @23TrevorE Před 7 lety +1

    Yet another brilliant tutorial, Corey. Many thanks.

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

    You just opened a whole new page of programming to me. Before this I didn’t fully understand oop. Thank you 👍

  • @antonisvenianakis1047
    @antonisvenianakis1047 Před 2 lety

    Thank you. Everyone is right here at the comments saying how good your videos are. I can only be grateful

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

    Mr.Corey, You did magic with OOP....really...it's very informative....THE BEST PYTHON series..... I never Watched........Thanks...a lot...& also do more on Machine learning and Datascience with Python

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

    That's a crystal clear explanation Corey....Really helpful

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

    Really clear and insightful explanations. Love it!

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

    Absolutely recommended video. Crisp and Clear

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

    Great tutorial, straight to the point. Thanks Corey!

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

    Really clean explanation. Thank you soo much!

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

    One of the best python program langauge channel on youtube, Thanks brother from India.

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

    Very useful tutorials! The pace and info is spot on and invaluable to me. Thank you!

    • @zes7215
      @zes7215 Před 5 lety

      ts not interesx or intimidax, no intimidax for such or anyx. diffix doesnt matter

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

    Each and every one of your videos is amazing. Thanks for the great content!

  • @clearair
    @clearair Před 6 lety

    Really amazing content Corey - really useful detail presented a brisk pace. Thanks so much!

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

    Thnx for the video Corey, now i can understand the special methods a little bit

  • @vm7240
    @vm7240 Před rokem

    Thanks a bunch! Your videos are to the point, concise and yet, very well explained.

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

    @corey - Your way of explaining the concepts are too good. Keep continue your work.Love your teaching skills. Kudos to you.

  • @kibuzz3258
    @kibuzz3258 Před rokem

    your python tutorials are greatest, thank you so much!

  • @Jeganbaskaran
    @Jeganbaskaran Před 7 lety

    Simply amazing!! The way you are representing anyone who can learn easily, I came from different language background and i can easily compare it the way you explained. Thanks for your videos. Keep it up.

  • @vladn.2332
    @vladn.2332 Před 6 lety +1

    Thank you for your videos, Corey! It really helped me better understand how to work with classes in Python :)

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

    great tutorial! I built my first app learning from your videos. Thank you!

  • @Burgturdler2
    @Burgturdler2 Před rokem

    Dude, you're awesome. Been binging your videos and they are helping a bunch. Excellent teaching ability!

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

    You deliver the best explanations and clear presentations.

  • @biswajitpaul3843
    @biswajitpaul3843 Před 7 lety +7

    All your videos are very useful. Keep it up.

  • @nit235
    @nit235 Před 3 lety

    We have to create another class to remove from CZcams those who watched this video but didn't thank Corey.
    Thank you a lot Corey ! I'm a beginner not only in python, but in all programming languages , but I understood your teaching very well.

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

    HUGE "ah-hah" moments going on here for me anyway. THANK YOU SIR!!!!

  • @yingjianhuang9030
    @yingjianhuang9030 Před 2 lety

    Thanks for video, I was so confused about these magic methods previously.

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

    When I was self studying C# because my job needed it, I hardly grasped the concept of OOP because coding it in C# to see how it actually works is complicated. With your explanation, I saw the clear and complete picture of OOP. Maraming Salamat ! (Thank you so much ! 🙂)

  • @AJ-et3vf
    @AJ-et3vf Před 2 lety +1

    Awesome video! Thank you!

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

    Really Awesome, Amazing flow of wording and content presentation. Thank you very much Schafer.

  • @loganinn3940
    @loganinn3940 Před 4 lety

    I watch this on June 29, 2020, and now I understand why you need __add/len/str/repr__ in a class. Best 30 minutes of time spent on learn and taking note.

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

    My code was crap before this series. But its a good thing, makes me appreciate everything you're teaching here. Thank you

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

    You are great man!! You have helped me a lot in understanding many Python Concepts.

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

    Awesome tutorial.. superbly described oops concept... thanku very much..

  • @bhaskargarai8371
    @bhaskargarai8371 Před 4 lety

    This guide helped me a lot....Showing appropriate examples for the methods...especially this one,and not only clear concepts,but also the way to make something understand is excellent....great job....

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

    Thank you, sir. Your video really helps me to have a better understanding of the special methods.

  • @Allomerus
    @Allomerus Před 5 lety

    Excellent explanation Corey. Thanks for sharing this!

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

    although I don't have a very advanced level of understanding of the English language, these tutorials are better than anyone in Portuguese, man, your tutorials are amazing, thanks so much!!

  • @dixonstroi
    @dixonstroi Před 3 lety

    another great tutorial. really helping to tie together learning from text tutorials and excercises.

  • @neorayohaion3141
    @neorayohaion3141 Před 3 lety

    DUDE HUGE THANK YOU I FINALLY MANAGED TO UNDERSTAND THAT THING TY SO MUCH!!!!!

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

    One of best explanation learning video to understand class and object

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

    excellent video- crisp points and ex. thanks very much

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

    It really helped me :) ... I thought I can't understand this topic but you made It clear

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

    These are excellent videos. Thank you!

  • @Dynamic.32
    @Dynamic.32 Před rokem

    Great tutorial, it's rare to see tutorials demonstrate how it's implemented on real modules

  • @misterjaypeasmith
    @misterjaypeasmith Před 4 lety

    You make learning Python really enjoyable Corey 🙌🏽

  • @stebe1919
    @stebe1919 Před 3 lety

    Great Video! You make it really fun to learn code.

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

    Great tutorial. Thank You.

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

    Really useful video. Well explained - thank you!

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

    daamnnnn, wow
    this video was specifically very informative and full of some deep stuffs...
    thanks....

  • @markcsizmadia2109
    @markcsizmadia2109 Před 7 lety

    this is just awesome! helps me a lot. thank you for your hard work!

  • @MrI7asson
    @MrI7asson Před 4 lety

    Great video as usual, explaining the data model in Python, Thank you so much.

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

    Awesome...Now I can see the more details and depth in python...

  • @anjanghosal5684
    @anjanghosal5684 Před 7 lety

    Excellent tutorial set! Please keep them coming ....