OOP in Python - Classes, Objects, class methods, monkey patching & more!

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ม.ค. 2025
  • 𝙎𝙞𝙜𝙣 𝙪𝙥 𝙛𝙤𝙧 𝙎𝙤𝙘𝙧𝙖𝙩𝙞𝙘𝙖 𝘾𝙤𝙪𝙧𝙨𝙚𝙨: www.socratica....
    𝙎𝙤𝙘𝙧𝙖𝙩𝙞𝙘𝙖 𝙋𝙮𝙩𝙝𝙤𝙣 𝙨𝙝𝙞𝙧𝙩: shop.socratica...
    In this tutorial on object-oriented programming (OOP) in Python, we use the analogy of making cookies to explain the concepts of classes and objects. This allows you to understand the distinction between classes (cookie cutters) and objects (cookies). We go on to explain how to define classes, create objects, and utilize methods. Additionally, this video covers the use of class attributes, instance attributes, class methods, and instance methods. Special cameo by monkey patching!
    𝙋𝙧𝙤𝙜𝙧𝙖𝙢𝙢𝙞𝙣𝙜 𝙥𝙡𝙖𝙮𝙡𝙞𝙨𝙩𝙨:
    Python: bit.ly/PythonSo...
    SQL: bit.ly/SQL_Socr...
    Subscribe to Socratica + bell for notifications:
    bit.ly/Socratic...
    ⧓⧓⧓⧓⧓
    We recommend:
    How to Be a Great Student
    ebook: amzn.to/2Lh3XSP
    Paperback: amzn.to/3t5jeH3
    Kindle Unlimited (read free): amzn.to/3atr8TJ
    Python Cookbook, 3rd edition
    amzn.to/3jprjX2
    More Socratica Python goodies here:
    shop.socratica...
    ⧓⧓⧓⧓⧓
    Join this channel to get access to perks:
    / @socratica
    Support Socratica on Patreon:
    / socratica
    Python instructor: Ulka Simone Mohanty (@ulkam on Twitter)
    Written & Produced by Michael Harrison
    Edited by Megi Shuke and Michael Harrison
    #python #pythonprograming #OOP

ความคิดเห็น • 84

  • @Socratica
    @Socratica  10 หลายเดือนก่อน +5

    𝙎𝙞𝙜𝙣 𝙪𝙥 𝙛𝙤𝙧 𝙎𝙤𝙘𝙧𝙖𝙩𝙞𝙘𝙖 𝘾𝙤𝙪𝙧𝙨𝙚𝙨: www.socratica.com/collections
    𝙎𝙤𝙘𝙧𝙖𝙩𝙞𝙘𝙖 𝙋𝙮𝙩𝙝𝙤𝙣 𝙨𝙝𝙞𝙧𝙩: shop.socratica.com/products/python-by-socratica

  • @soyuzssr
    @soyuzssr 10 หลายเดือนก่อน +46

    I’m so happy !! A new Socratica Python video dropped !! Please do more such videos - they’re really so helpful !

  • @omhmpp
    @omhmpp 10 หลายเดือนก่อน +25

    Always happy to see ulka back with a programming video

  • @2A9D8F
    @2A9D8F 10 หลายเดือนก่อน +18

    Best channel in youtube. I wish you guys made an app so I would use it instead of getting distracted by youtube shorts :D

    • @Socratica
      @Socratica  10 หลายเดือนก่อน +7

      We're working on a course page as we speak! Thanks for your kind words.

  • @ahmetahmed9754
    @ahmetahmed9754 9 หลายเดือนก่อน +1

    I'm really amazed by the way they made this video. It tells nothing but their mystery of the concept. The moment you are able to simplify the concept is the moment you earn the master of the concept title.
    Well done! And I'm glad to be part of the Socratica family.

  • @dmitrii3517
    @dmitrii3517 วันที่ผ่านมา

    Ulka is the best Python instructor ever!❤

  • @Allen-by6ci
    @Allen-by6ci 10 หลายเดือนก่อน +10

    Ulka is awesome as usual. Please list her in the credits.

    • @Socratica
      @Socratica  10 หลายเดือนก่อน +3

      She is! Please visit our illuminating Description box for lots of details.

  • @Zancb
    @Zancb 10 หลายเดือนก่อน +2

    Yay!!! I'm so happy to see a new video from Socratica!

  • @dewaynescott5114
    @dewaynescott5114 10 หลายเดือนก่อน +1

    Thank you so much for these videos. I can’t even express how appreciative I am. Please keep them coming and this format for learning is perfect.

  • @TheWyrdSmythe
    @TheWyrdSmythe 9 หลายเดือนก่อน

    A nice concise overview of Python classes in only eleven minutes! 👏🏼👏🏼👏🏼

  • @mohammadamanalimyzada1462
    @mohammadamanalimyzada1462 10 หลายเดือนก่อน +5

    Please do speed up uploading more amazing videos like this
    I love the job you guys are doing here and appreciate it from the core of my heart🥰🥰🥰

  • @pineablesoda
    @pineablesoda 4 หลายเดือนก่อน

    this is such an amazing video, this along with the decorators one and a few others are awesome, I'm studying CS and I'm in my first ever semester of university and they're teaching python, it's a lot of content to understand but these videos help out a lot! like learning classes from my book and the uni lecture took me 3hours almost, but this video made me understand it much better in just 11 minutes, its insane.

  • @StwongDave
    @StwongDave 10 หลายเดือนก่อน +5

    As an App Dev, I will 100% be using "software thingies" to describe what I'm doing now.

    • @emman100
      @emman100 10 หลายเดือนก่อน +2

      I was thinking of a way to explain what objects are without being technical and yes, I would also call them software thingies. 🤣

  • @Mohammad2525
    @Mohammad2525 9 หลายเดือนก่อน

    Sent it to some friend and help him a lot. Outstanding explaining like always. You guys are awesome behind and in the front of Socratica Channel.

  • @DrDeuteron
    @DrDeuteron 6 หลายเดือนก่อน

    3:03 thank you so much for disambiguating "parameter" and "argument". Up next: dunder next, dunder iter, iterabale vs iterorator .....

  • @flarone
    @flarone 10 หลายเดือนก่อน +1

    This series is really great.

  • @murphygreen8484
    @murphygreen8484 10 หลายเดือนก่อน

    Man, those dunder methods are really magical

  • @amarmusovic7748
    @amarmusovic7748 7 หลายเดือนก่อน

    I want every single thing I'm going to learn for the rest of my life explained by Ulka. 😀

  • @1cookgs
    @1cookgs 5 หลายเดือนก่อน

    Excellent presentation! Thank you.

  • @wahwahwally1
    @wahwahwally1 6 หลายเดือนก่อน

    Great video! Easiest sub of my whole life...

    • @Socratica
      @Socratica  6 หลายเดือนก่อน

      Thank you Socratica Friend!! 💜🦉

  • @JorgeEscobarMX
    @JorgeEscobarMX 10 หลายเดือนก่อน +1

    Very well done, explained. A second part with the explanation of creating and using the dunder methods: __repr__, __str__, etc would be great.

    • @emman100
      @emman100 10 หลายเดือนก่อน +1

      Those methods have great responsibility attached to them. 😁

  • @angojones3713
    @angojones3713 10 หลายเดือนก่อน +2

    Like button activated, comment section engaged. Ready for takeoff.

    • @DrDeuteron
      @DrDeuteron 6 หลายเดือนก่อน

      *like button activated mod 2 times.

  • @shawnscientifica7784
    @shawnscientifica7784 9 หลายเดือนก่อน

    I feel in love with this channel years back and forgot due to life and school and now I'm back? I'm ready to fully invest! This is the kind of learning I would happily pay for!!
    Just went to your site, will you eventually do more advanced courses? say, an explanation of Topology, or AI/ML Python in this format. I love the scifi theme or any artistic theme it satisfies the artist in me and the Engineer I am by degree is satisfied by the information. You do a holy work here, divine by the universe

  • @techjunk8467
    @techjunk8467 9 หลายเดือนก่อน

    Understanding OOP makes me smile

  • @GenZ_01_
    @GenZ_01_ 7 หลายเดือนก่อน

    As always high high quality!

  • @9jatechie
    @9jatechie 10 หลายเดือนก่อน

    Thanks for the beautiful video and welcome back.

    • @Socratica
      @Socratica  10 หลายเดือนก่อน

      Thank you Socratica Friend!!! 💜🦉

  • @pile333
    @pile333 10 หลายเดือนก่อน +1

    Very well done! 👏

  • @emman100
    @emman100 10 หลายเดือนก่อน +1

    Excellent video. I did not know that for self, you can pass in whatever name you want. I will still use self as it is convention but that is quite interesting. It does not seem to be the same for cls though. I started using Python OOP like 2 years ago. They make my code look so clean. 😁

  • @joaovazquez7112
    @joaovazquez7112 9 หลายเดือนก่อน

    Que video legal.
    Continuem com essa série, por favor, pois muito agradável o aprendizado.
    Obrigado

  • @Gtv7020
    @Gtv7020 5 หลายเดือนก่อน

    This is pure Gold. So elegant and clear. My question is, do you have a course I can signup that is not on TH-cam? I checked Socratica collections and I only see what is on TH-cam

  • @crackintosh
    @crackintosh 10 หลายเดือนก่อน

    I love Socratica!

  • @hibryd7481
    @hibryd7481 10 หลายเดือนก่อน +1

    This is very fortuitous; I've had a little spare time and was thinking of playing around with game design, a field in which OOP is applied liberally. I honestly don't use OOP that much and need to brush up, and it seems Python has a somewhat different feature set regarding OOP than other languages I've used in the past.
    To drift outside the scope of this video and wax on a little bit about design; I'd highly recommend to newer programmers to only utilize OOP when it makes clear and obvious sense to do so. There are schools of thought that OOP is the biggest tragedy to ever befall the programming community, and while I think that's a bit extreme, it has been my experience that OOP gets applied to a *very* wide range of situations where it isn't necessary or appropriate.

    • @DrDeuteron
      @DrDeuteron 6 หลายเดือนก่อน

      OOP can be screwed up, but if you keep it S.O.L.I.D, it does well. My tips (and I know _you_ already know these):
      Strategy:
      >SRP: a class should have 1 purpose. No God objects, no scripts-in-a-class (the hardware ppl violate this all the time)
      >LSP: look it up.
      >Avoid object envy and inappropriate intimacy (don't mix two class's purposes)
      >Law of Demeter (keep it shallow) self.other.item.coins is bad
      >Has-A is better than Is-A (Is-A is so tempting when you learn about inheritance)
      >no race hazards in method calls (unless it's factored private method calculation)
      Tactics:
      >Lead with dunder init in the code (after class attributes--so 1st "def" is init).
      >Have it construct the whole object: no post init attribute injection.
      >do not do work in init.
      --if 2 and 3 are too hard, provide a class method constructor helper.
      >anything the object needs to do should be in a method.
      >method are the only place for side effect: only mutate attributes in the object _own_ methods, don't mutate other object from the parameters, never mutate "self" in a function.
      >push calculations up the method stack as far as possible.
      >YAGNI: don't add functionality before you need it, or know what it's going to look like.
      Other:
      Avoid primitive exception, e.g. don't make a phone number an integer, it looks like one, but it is not. Don't make it a "list" where you have to rememeber indices [area code, prefix, 4 digits], don't make it a dictionary {'area code': 800, 'prefix": 555,,,}...a class is a dictionary, so make it a class.
      ofc I have violated ALL of these, and have suffered as a result.

  • @AlexanderBukh
    @AlexanderBukh 10 หลายเดือนก่อน

    fabulous stuff, thanks!

  • @FirozBhati-x9m
    @FirozBhati-x9m 9 หลายเดือนก่อน

    your fitness is amazing you still look same as 6 years back.

  • @juanmacias5922
    @juanmacias5922 10 หลายเดือนก่อน +1

    Whooo! New Python video. :D

  • @deepdatasoftware2553
    @deepdatasoftware2553 9 หลายเดือนก่อน

    Thank you Socratica, great material and very nice way of teaching. I am wondering why "introduction" as being a instance method is getting printed when calling "dir(Person)", I would've thought that only class methods will be printed, Do you know why this is happening? Thank you very much in advanced. Regards

  • @TekluEng
    @TekluEng 5 หลายเดือนก่อน

    This is just an awesome stuff. By the way do you have any other Python course that is not on TH-cam? I have seen the website but I can't find anything that is not here. I wanted to sign up for Python 2 and Python 3 but none of them seem to be published yet.

  • @dixztube
    @dixztube 10 หลายเดือนก่อน

    i always enjoy coding in python - its a fun language. i guess they each have their enjoyable idiosyncrasy... golang is also fun. js isn't fun to me but the project goals can be made fun. i havent done any ML work but i hear mojo is super cool

  • @Omnifarious0
    @Omnifarious0 9 หลายเดือนก่อน

    I can understand the pleasing symmetry of covering instance methods and class methods. Class methods are generally fairly uncommon though, and it's a lot more common to have static methods. Sadly, those don't fit the pleasing symmetry nearly so well. 😕
    Otherwise, as always, I loved your presentation. :-)

  • @mikloslipcsey7923
    @mikloslipcsey7923 5 หลายเดือนก่อน

    So if the double underscore is at the beginning of the function or program, does that make it a dunderhead?

  • @d55ai
    @d55ai 7 หลายเดือนก่อน

    any chance we can know what font you are using?

  • @acherongoon
    @acherongoon 9 หลายเดือนก่อน

    I love the videos and would like to use them with students; unfortunately in recent feedback we seem to have an "uncanny valley" effect, highlighted when we studied the effect in robotics... it causes a disconnect with students and to some level a distrust of the information, explanations not being fully recognised.

  • @israelortiz8820
    @israelortiz8820 10 หลายเดือนก่อน

    Welcome back

  • @iamjimgroth
    @iamjimgroth 10 หลายเดือนก่อน +1

    It is indeed responsible to create classes.

  • @GegeOriloye
    @GegeOriloye 9 หลายเดือนก่อน

    Impressive! Thanks.

  • @mjkluck
    @mjkluck 10 หลายเดือนก่อน +1

    Good stuff.

  • @ChakradharrChakrii
    @ChakradharrChakrii 10 หลายเดือนก่อน

    Awesome 🎉

  • @sinaasadiyan
    @sinaasadiyan 10 หลายเดือนก่อน

    great video

  • @emman100
    @emman100 10 หลายเดือนก่อน +1

    I did not know about monkey patching lol. These Python OOP nicknames are out of control. 🤣

  • @waqarkhanpisces
    @waqarkhanpisces 9 หลายเดือนก่อน

    how do you get the idea of this type videos, whenever i visit here i think that a horror movie is being played your hard work is very appreciable

  • @CerejaStudies
    @CerejaStudies 9 หลายเดือนก่อน

    pq abandonaram os brs? gostava tanto dos videos

  • @tomoki-v6o
    @tomoki-v6o 3 หลายเดือนก่อน

    how to deploy python library ?

  • @atlantic_love
    @atlantic_love 4 หลายเดือนก่อน +1

    The AI-emulating mistress we always wanted.

  • @hellocodeur
    @hellocodeur 9 หลายเดือนก่อน

    Thanks

  • @jeffschroeder4805
    @jeffschroeder4805 10 หลายเดือนก่อน

    Strange to see your name used in an example. You are welcome!

  • @DrDeuteron
    @DrDeuteron 6 หลายเดือนก่อน

    You down with the O.O.P (yeah you know me)
    You down with the O.O.P (yeah you know me)
    You down with the O.O.P (yeah you know me)
    You down with the O.O.P (yeah you know me)
    You down with the O.O.P (yeah you know me)
    You down with the O.O.P (yeah you know me)
    Who's down with the O.P.P. (all the homies).

  • @kirbymarchbarcena
    @kirbymarchbarcena 10 หลายเดือนก่อน

    Now I crave for cookies

    • @Socratica
      @Socratica  10 หลายเดือนก่อน

      Us toooo oh no
      Our friend just sent us a recipe for masala chai shortbread!

    • @kellysmith7357
      @kellysmith7357 10 หลายเดือนก่อน

      orly

  • @lucasgaperez
    @lucasgaperez 9 หลายเดือนก่อน

    you never came back to your spanish channel😢

  • @ChandrashekarCN
    @ChandrashekarCN 10 หลายเดือนก่อน

    💖💖💖💖

  • @DrDeuteron
    @DrDeuteron 6 หลายเดือนก่อน

    2:37 full_name? You doing work in dunder init? Nooooo!!!!! Make that a property or functools.cached_property, or, if it works, make it the output of dunder str.
    I don't do work in the init. It's a slippery slope. Oh, it's just adding two attributes---next thing you know you're opening resources on a Timbuktu server and doing giga-flop calculations and your whole abstraction grinds to a halt.

  • @king1_one
    @king1_one 9 หลายเดือนก่อน +1

    bro i am in future and i have a AI teacher.

  • @destinliburd5455
    @destinliburd5455 10 หลายเดือนก่อน

    ❤❤❤heart

  • @sirk3v
    @sirk3v หลายเดือนก่อน

    lit

  • @kellysmith7357
    @kellysmith7357 10 หลายเดือนก่อน

    noice

  • @LanguageHelp
    @LanguageHelp 10 หลายเดือนก่อน +2

    first

    • @raj-zo4ev
      @raj-zo4ev 10 หลายเดือนก่อน

      😂

  • @benjamingoldstein1111
    @benjamingoldstein1111 10 หลายเดือนก่อน +4

    I must say that the robotic design of the otherwise excellent videos is really distracting.

    • @okaytokay
      @okaytokay 10 หลายเดือนก่อน +14

      Nah.. you must be new. This is perfect.

    • @Allen-by6ci
      @Allen-by6ci 10 หลายเดือนก่อน +4

      Ulka is awesome

    • @benjamingoldstein1111
      @benjamingoldstein1111 10 หลายเดือนก่อน +1

      @@Allen-by6ciThis is naturally very subjective. I could do with fewer sound bits and I'd rather hear a more natural voice modulation. The older videos were not this over-produced. But it's great if you like it the way it is. Just my two cents.

    • @hibryd7481
      @hibryd7481 10 หลายเดือนก่อน

      I think its fun; its definitely preferable to not having any style at all. If you code a lot you know what a slog it can be to wade through endless tutorials with someone just speaking dryly at length over an unedited screencap.

    • @benjamingoldstein1111
      @benjamingoldstein1111 10 หลายเดือนก่อน

      @@hibryd7481Yes, there is a soft spot somewhere in between.