Difference between function and method in Python. Is it just self?

preview_player
Показать описание
What happens in Vegas, stays in Vegas. Methods are functions in objects and take care of their state via the self parameter. Regular functions can live anywhere in your code. They process input and return output. This video shows the difference between functions and methods.

C H A P T E R S
0:08 What is a function?
0:28 Function with side effects
2:35 What is a method?
3:38 What is self?
4:04 Where are instance methods stored?
5:35 Why does an instance method expect self as the first parameter but when it is called, self does not have to be passed as an argument?
6:10 Functions v.s. Methods
6:52 Does it have to be named 'self'?

M Y O N L I N E T R A I N I N G

#pythonforeveryone #programming #python
Рекомендации по теме
Комментарии
Автор

Really an awesome video from 2-3 days i am stuck in oops in this topic methods and function, (self ) specially, and other stuff but now i understand . Thanks for uploading.

Meditechy
Автор

nice vid, got me to understand this topic

ЭрикКоляда-жю
Автор

Sir, have viewed your vid over a few times now and I have been assuming there is always a good reason for something if implemented by the creators whether it be software or hardware and in the quest to understand this chaotic mess of a language I think you really hit on the exact question I haunt myself with, and I guess if i do, then I am far from alone, and that is at 4:39 in your excellent vid, why oh why oh why is it required for 'self' to needed to be anywhere at all in the class method as from the 'calling' object ( yep I guess that's the pythonic wrong way to describe things ) it surely is 'implied'. Is there something i am missing here, is there any possible way to create a class instance/object/mess whatever you call it in python and use it on the wrong instance, I cannot see how there can be any way of 'crossing' over for the call to get confused with any other instances in the program as they, well you, will have to give them unique names so why the need for 'self', so as you are a true master with python can you for a pleb with 40+ years in C explain if there is any way to call/use a class from it's object where you could create a situation where the ?call? to the class method could in any way be crossed, ibeing that as you say in the vid that python passes is without you knowing, so it's implied surely no possible way to mix up, surely it can't happen. But as I am a complete *** in this regard could I ask if you have any examples or references where this could happen, such that I may 'see the light' like so many 'think' they can as I feel that 'self' could have been left in the virtual trash can with no real reason to be there which I guess would be saving python programmers untold billions of 'self' typing in their code over the years. I am genuine when I say I am being far far from trying to be clever and really respect your clear and well paced tutorials, my rant is that this cryptic implementation of a language that it is required to need this amount of deciphering tutorials as it is supposed to be so easy ???.
To sum up, I have learned some very interesting and valuable snippets from your 2 or 3? now videos I have seen so far and I would consider that no one could do more. Now i'll throw another spanner in the works that I think most people that watch learning videos on python and think they know but I bet that most don't and that is 'namespace' I guess you may have video on that, have you ever googled, open.ai'd that subject, oh, you get an answer that no one without a doctorate in code deciphering will ever get anywhere near explaining, I would love to hear you thoughts on this one that I am also battling with in this beginners easy to use and understand ? language ?, and I feel half the planet is also in misunderstanding if they owned up. Many many thanks for your commitment to try and help us dipsticks. I shall await for any pointers to the above. Kind Rgds.

joeking
Автор

This video is great, but i do have one complain...

Try making letters in white and the background in black. Because rewatching this is a little bit painful and not confortable at all!

Great video tho

popsicle
Автор

Thank you so much for the try, but totally 'Lost in Space' no idea what the hell they/he/she were thinking or what meds was on when this cryptic, ambiguous, confusing language was developed, and this is a so called 'modern' language, the joke is back in the day C was shot to pieces for the same reasons, I guess that you sir are a professional programmer and if so I guess that you have use this nightmare and I would imagine are grateful when the job calls for decent language to be used, my sympathy goes out you with having cope with this obfuscation. Kind Rgds.

joeking