Please Master This MAGIC Python Feature... 🪄

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

КОМЕНТАРІ • 60

  • @TechWithTim
    @TechWithTim  4 дні тому +5

    Click this link sponsr.is/bootdev_TechWithTim and use my code TECHWITHTIM to get 25% off your first payment for boot.dev.

  • @supermalavox
    @supermalavox 4 дні тому +41

    Good audiodescribing of what you're teaching; very accessible for blind people (whose screen readers don't read the internal contents of videos); it helps us learn programming concepts and tricks as you go. Keep up the good work!

  • @baumgrt
    @baumgrt 2 дні тому +2

    11:16 in general, you’d expect addition to return an object of the same type, i.e. a new counter whose value attribute is the sum of the two value attributes of self and other. If implemented like shown here, directly returning the sum of the value attributes as an integer, addition won’t work with more than 2 terms. For example, a + b + c or sum([a, b, c]) will throw an error because the types aren’t compatible. Also, don’t forget to implement subtraction when working with number-like objects.

    • @SamMason0
      @SamMason0 День тому

      Probably want to raise the proper NotImplemented exception to let Python understand what's going on and let the RHS have a go at implementing the operation

    • @baumgrt
      @baumgrt День тому

      @ You can’t control what happens in this case because the first addition works as specified and the second one will probably raise a TypeError because int doesn’t know how to add itself to some random object. You can only check and control what happens when your class is on the left side of the operator. Personally, I’d rather define a dedicated method than using the add dunder if I wanted the operator to return something outside of my class for some legitimate reason.

  • @onetruetroy
    @onetruetroy 4 дні тому +5

    Excellent video. The concept that all operations are functions that take objects as arguments just opens up the language and syntax. I think I’m going to like Python considering how I prefer to learn, which is to achieve mastery, not perfection nor expecting success the first time.

  • @freguenshoodjean5841
    @freguenshoodjean5841 4 дні тому +7

    Thank you I learn a lot from you Tim.

  • @AAS-wl3vq
    @AAS-wl3vq 4 дні тому +2

    I like the advanced comparison to simple py functions. Easy to understand. Thanks for all your awesome content

  • @eziola
    @eziola 3 дні тому +1

    I love basic "under the hood" videos like this. I've tried to figure this stuff out by going into the standard library modules and reading the source code. Also by using dir() and looking at all the objects that exist. Hopefully more videos like this!

  • @peytonporter6778
    @peytonporter6778 День тому +2

    Missed opportunity to try and compare apples to oranges

  • @7th_dwarf542
    @7th_dwarf542 День тому

    Very concise and illustrative. Thank you for sharing your knowledge

  • @davidlu1003
    @davidlu1003 3 дні тому

    Tim:"So just to prove to you that I'm not crazy..."🤣🤣🤣Absolutely, I agree with you.😆😆😆

  • @dangodono6096
    @dangodono6096 4 дні тому

    Honestly love your vids, i’ve learned tons of things from you!

  • @jana171
    @jana171 4 дні тому

    This was REALLY good... Knowing why it works supercharges the using of it. Well done, thanks !

  • @ScottLahteine
    @ScottLahteine 2 дні тому

    It would be interesting to see a distinction between cases where you would want to have an array of objects versus wrapping an array of objects in another object that behaves like an array.

  • @MouriYazid
    @MouriYazid 4 дні тому

    Wow tnks i get a lot of info everytime i watch ur vids i love python and u made it easier for me

  • @mohammedhewija2667
    @mohammedhewija2667 3 дні тому

    that helpfull topic , thanx tim , keep this way , this is very good content

  • @gauravshaurya
    @gauravshaurya 4 дні тому

    You are really helping me in raising my bar in Python.

  • @liberatemi9642
    @liberatemi9642 2 дні тому +1

    Nice - so essentially it supports operator overloading, IDispose, IEnumerable and indexer overloading.

  • @davidlu1003
    @davidlu1003 3 дні тому

    Great topic, bro.😁😁😁Useful and helpful.

  • @h.m.6228
    @h.m.6228 3 дні тому +2

    Operator overloading FTW

  • @davidlu1003
    @davidlu1003 3 дні тому

    Bro, you are not just not crazy but also you are a genius. I learn something from you. That is why I want to laugh what you said.😁😁😁Keep going, very helpful.

  • @sunilanthony17
    @sunilanthony17 3 дні тому +1

    so init is like a constructor?

  • @A__GARV_SAXENA
    @A__GARV_SAXENA 4 дні тому +3

    Thank you sir :D

  • @dragonraopen2604
    @dragonraopen2604 2 дні тому

    Is there any book to lear all meaning of python programming ?

  • @skewtee
    @skewtee 4 дні тому

    Great info, thanks much

  • @ShadowriverUB
    @ShadowriverUB Годину тому

    Its technicly equivlent of operator overrides in c++

  • @davidestrada4906
    @davidestrada4906 4 дні тому

    what a good video congrats!

  • @akinyemiayomide9829
    @akinyemiayomide9829 4 дні тому

    Thanks a lot for this content

  • @OmidAtaollahi
    @OmidAtaollahi День тому

    great. Tnx🙂

  • @as_wani
    @as_wani 4 дні тому

    Very detailed 👍

  • @pratikpatil8395
    @pratikpatil8395 3 дні тому

    You are really amazing TIm thanks a lot you some up with something new

  • @kevinh5212
    @kevinh5212 4 дні тому +2

    Tim using classes to flex his 2021 Toyota Corolla on us peasants 😭

  • @RN-er7mz
    @RN-er7mz 4 дні тому

    I know this stuff but still watched ❤, loved your content

  • @Abd_Elhameed
    @Abd_Elhameed 4 дні тому

    Nice video, thank you

  • @azharalibhutto1209
    @azharalibhutto1209 4 дні тому +1

    Great ❤❤❤

  • @we__do
    @we__do 4 дні тому

    Creature feature featuring the Creature

  • @Darth_Bateman
    @Darth_Bateman 4 дні тому

    Dunder Dunder DUNDER DUNDERCATS HOOOOOOOO

  • @TheCaesarChris
    @TheCaesarChris 3 дні тому

    Why does print(count1+ count2) not call the __add__ and then the __str__ dunder?

    • @baumgrt
      @baumgrt 2 дні тому

      It does, but not the way you expect. Counter.__add__ returns an integer (the sum of the values attributes) instead of another Counter object. That’s why the string method of int is called and not the one of Counter.

    • @TheCaesarChris
      @TheCaesarChris 2 дні тому

      @ thanks for the reply and that makes sense!

  • @TheCaesarChris
    @TheCaesarChris 3 дні тому

    Really great video, subscribing for more content like this! 👏

  • @cruz1ale
    @cruz1ale 3 дні тому

    The eyebrows really carry these thumbnails

  • @bbriambbriam
    @bbriambbriam 4 дні тому

    Just pure gold

  • @sanjaygatne1424
    @sanjaygatne1424 3 дні тому

    instead of dunder methods why not direct use [], +, - in def function.

  • @KmartShopper726
    @KmartShopper726 18 годин тому

    Did anyone else slightly panic when the add implementation didnt return the same type of objects being added?
    Good video overall though

  • @KhanyisileMadikane
    @KhanyisileMadikane 3 дні тому +1

    I don't know why but I'm really not getting it😭

    • @richardconway6425
      @richardconway6425 3 дні тому +1

      Don't worry. Classes are a difficult subject to understand for us non-programmers. The whole paradigm of object oriented programming (OOP) is difficult to understand. At first sight, it seems to make what should be a simple task into something way too complicated.
      I was doing fine with python until I tried to understand classes and why I should use them.

  • @Dunning_Kruger_Is__On_Youtube
    @Dunning_Kruger_Is__On_Youtube 3 дні тому

    Did your sponsor make you delete my previous comment regarding their prices or was that you?

    • @TechWithTim
      @TechWithTim  3 дні тому

      I never left a comment about their prices nor deleted any comments

  • @foqsi_
    @foqsi_ 3 дні тому

    egg sit

  • @janni7439
    @janni7439 День тому

    Regarding arithmetic operators: there are languages with huge support of such operators, I know F# and Kotlin for instance. While Java has not. The conclusion is, to not overuse such stuff, since it's not only hiding complexity, but practically hides the concrete implementation - which not only makes it hard to follow the code, but could also lead to really hidden bugs.

  • @recyclebin
    @recyclebin 4 дні тому

    Is that how we're pronouncing integer, now?

  • @MartinWoad
    @MartinWoad День тому

    __python__ __is__ __unreadable___