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!
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.
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
@ 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.
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.
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!
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.
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.
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.
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.
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.
Click this link sponsr.is/bootdev_TechWithTim and use my code TECHWITHTIM to get 25% off your first payment for boot.dev.
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!
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.
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
@ 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.
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.
Thank you I learn a lot from you Tim.
Very welcome
I like the advanced comparison to simple py functions. Easy to understand. Thanks for all your awesome content
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!
Missed opportunity to try and compare apples to oranges
Very concise and illustrative. Thank you for sharing your knowledge
Tim:"So just to prove to you that I'm not crazy..."🤣🤣🤣Absolutely, I agree with you.😆😆😆
Honestly love your vids, i’ve learned tons of things from you!
This was REALLY good... Knowing why it works supercharges the using of it. Well done, thanks !
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.
Wow tnks i get a lot of info everytime i watch ur vids i love python and u made it easier for me
that helpfull topic , thanx tim , keep this way , this is very good content
You are really helping me in raising my bar in Python.
Nice - so essentially it supports operator overloading, IDispose, IEnumerable and indexer overloading.
Great topic, bro.😁😁😁Useful and helpful.
Operator overloading FTW
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.
so init is like a constructor?
This video is for Python "programmers"
__init__ is constructor class method in python,
Thank you sir :D
Most welcome!
Is there any book to lear all meaning of python programming ?
Great info, thanks much
Its technicly equivlent of operator overrides in c++
what a good video congrats!
Thanks a lot for this content
great. Tnx🙂
Very detailed 👍
You are really amazing TIm thanks a lot you some up with something new
Tim using classes to flex his 2021 Toyota Corolla on us peasants 😭
I know this stuff but still watched ❤, loved your content
Nice video, thank you
Great ❤❤❤
Creature feature featuring the Creature
Dunder Dunder DUNDER DUNDERCATS HOOOOOOOO
Why does print(count1+ count2) not call the __add__ and then the __str__ dunder?
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.
@ thanks for the reply and that makes sense!
Really great video, subscribing for more content like this! 👏
The eyebrows really carry these thumbnails
Just pure gold
instead of dunder methods why not direct use [], +, - in def function.
Did anyone else slightly panic when the add implementation didnt return the same type of objects being added?
Good video overall though
I don't know why but I'm really not getting it😭
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.
Did your sponsor make you delete my previous comment regarding their prices or was that you?
I never left a comment about their prices nor deleted any comments
egg sit
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.
Is that how we're pronouncing integer, now?
__python__ __is__ __unreadable___