Тёмный

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

Python for Everyone
Подписаться 5 тыс.
Просмотров 6 тыс.
50% 1

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
🎓Like my style of teaching? Try free chapters of my online courses: pythonforeveryone.com
#pythonforeveryone #programming #python

Опубликовано:

 

24 янв 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 12   
@python-for-everyone
@python-for-everyone Год назад
Checkout this video next: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-6NaHOObdpT8.html
@Meditechy
@Meditechy Год назад
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.
@pSL-oy5gl
@pSL-oy5gl 3 месяца назад
Clearly explained. Thank you
@user-fg1em3yg1c
@user-fg1em3yg1c 4 месяца назад
nice vid, got me to understand this topic
@princeardalan
@princeardalan 7 месяцев назад
Great video!
@joeking5211
@joeking5211 Год назад
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.
@joeking5211
@joeking5211 Год назад
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.
@python-for-everyone
@python-for-everyone Год назад
Self is a mysterious thing when you start with classes in Python. Perhaps you want to see an older video on my channel where I emulate classes. It makes it clear where self fits in: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-TTFo4KLm-2I.html
@joeking5211
@joeking5211 Год назад
@@python-for-everyone Hi Many thks for your reply, coincidentally I had viewed that vid between leaving my rant here and spotting this reply. So I guess you may have already seen my comment to that and my suggestion to all other viewers that share my bemused state. That video I am just totally confused from start to finish. That is in no way shape or form criticising your python or tutoring skills, quite the reverse, they are grade 1 +++, many thanks for your efforts in tying to explain the unexplainable to us thicko's. I would be very interested in your true thoughts on the implementation nightmare of python, do you think i am a total idiot for my thoughts / opinions or do you think there is good reason to air my findings for the new unwary python coders suffering this total confusion. Many many thanks again sir, you are a true master.
@joeking5211
@joeking5211 Год назад
One thing I notice that you did'nt answer is the thought I had with regard to reading the word 'self' as 'sender', do you not feel that sort of answers some of the confusion here, ie self is in fact replaced by the senders object name. I should like your view on this to verify if I am at least pointing somewhere in the right direction, or should tear that up and start again, and this may hopefully help any other many poor souls in the same confused state. Thks in advance.
@popsicle1809
@popsicle1809 Месяц назад
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
@python-for-everyone
@python-for-everyone Месяц назад
Thanks for the compliment and my newer video's use dark mode for your convenience.
Далее
How Strings Work in C++ (and how to use them)
19:26
Просмотров 453 тыс.
Functions vs Classes: When to Use Which and Why?
10:49
Просмотров 149 тыс.
5 Useful F-String Tricks In Python
10:02
Просмотров 288 тыс.
Add a Simple LOADING BAR To Your Shell Scripts!
16:26
Python Methods and self
13:48
Просмотров 43 тыс.
THIS is Why List Comprehension is SO Efficient!
5:25
Просмотров 171 тыс.
If __name__ == "__main__" for Python Developers
8:47
Просмотров 392 тыс.