No video

Still confused about "self" in Python? Then watch this!

  Рет қаралды 102,487

Python for Everyone

Python for Everyone

Күн бұрын

Self is a mysterious thing when you start creating classes in Python. In this video you learn why methods have self as first parameter and how Python passes a value for it automatically when calling the method.
D E E P E R D I V E:
Take a deeper dive into self by learning how bound methods work in Python: • How bound methods are ...
C H A P T E R S
0:28 What is self?
0:35 Why does a method have two parameters and when you call the method you only have to pass one argument?
1:29 The instance and the arguments are packed into a method object
F R O M T H E D O C S
"If the name denotes a valid class attribute that is a function object, a method object is created by packing (pointers to) the instance object and the function object just found together in an abstract object: this is the method object. When the method object is called with an argument list, a new argument list is constructed from the instance object and the argument list, and the function object is called with this new argument list."
docs.python.or...
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: pythonforevery...
#pythonforeveryone #programming #self

Пікірлер: 148
@natan.mendes
@natan.mendes 4 ай бұрын
clicked because the thumbnail seems like dostoievsky
@python-for-everyone
@python-for-everyone 4 ай бұрын
Haha, you are right. It does!
@EdwinCrown
@EdwinCrown 3 жыл бұрын
This was the most dummy proof explanation ever, after 8 youtube videos. This was the one with the eureka moment!!! Thanks Soooooo Much
@python-for-everyone
@python-for-everyone 3 жыл бұрын
That is a great compliment. Thanks!
@SriramTantri25
@SriramTantri25 Жыл бұрын
Literally the same feeling after 8 videos again!
@seeum
@seeum Жыл бұрын
same brooo, ngl i am still a bit confused but i understand it 10 times more than i did 2 min ago
@uncannyvalley3190
@uncannyvalley3190 Жыл бұрын
Happy for you because this video only made things more confusing
@dasnilpferd115
@dasnilpferd115 2 жыл бұрын
This is the best explanation of this that I have found. A lot of times when people make things really simple, they neglect actually explaining something and expect you to understand something just from seeing it. Thanks for making this helpful video!
@davidsanchezsimon1386
@davidsanchezsimon1386 2 жыл бұрын
Best explanation ever, you didn't need to mention unnecessary terminology (which often makes you feel more confused) to perfectly explain the topic. Congrats! and thanks for the help!
@python-for-everyone
@python-for-everyone 2 жыл бұрын
That is a really nice compliment! Thank you!
@bastou_chl6066
@bastou_chl6066 3 жыл бұрын
I started getting the concept before this video but to me this was very well and simply explained, congrats !
@dimaconaffetto
@dimaconaffetto Жыл бұрын
I watched a video 10-20 minutes long and did not understand anything. Here in 2 minutes I understood everything. Brilliant, thank you!
@umaraliarshad7454
@umaraliarshad7454 Жыл бұрын
After a year i have found the right answer.. bro I really love you... Keep it up.
@eliaskarlsson9463
@eliaskarlsson9463 2 жыл бұрын
I LOVE YOU MAN! I have been trying to understand this for so long now without any success. Finally I found you video and understood instantly. Thank you
@brandon9638
@brandon9638 2 жыл бұрын
Even with this simple explanation, OOP is still confusing...
@python-for-everyone
@python-for-everyone 2 жыл бұрын
OOP can be quite confusing. It took me over 20 years before I understood its true purpose. That said, 'self' is just a mechanism in Python. You can ignore it and focus on the main topics of OO, like polymorphism and inheritance.
@osmarramoa434
@osmarramoa434 5 ай бұрын
Master, legend... you brought light to my dumb brain. Thank you so much!
@wesleypresleymusic4940
@wesleypresleymusic4940 2 жыл бұрын
Thank you. Best 2 minute explanation ever.
@emirzarahman516
@emirzarahman516 3 жыл бұрын
Well this is explained in a very concise way, deserves a like and subscribe, thanks!
@python-for-everyone
@python-for-everyone 3 жыл бұрын
Thank you so much for the kind words!
@setripper
@setripper 2 жыл бұрын
Best explanation ever!
@python-for-everyone
@python-for-everyone Жыл бұрын
Thank you!
@kylerasinger5256
@kylerasinger5256 2 жыл бұрын
Appreciate that you repeat yourself. Im sure it was the difference between understanding and not understanding for many.
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thanks for that feedback. That is good to know!
@swedenludvig
@swedenludvig 2 жыл бұрын
Finally an explanation I understand. Thank you!
@VAIBHAVMALHOTRA19
@VAIBHAVMALHOTRA19 3 ай бұрын
Finally found the video where self is explained properly
@ROHITKUMAR-mu7ik
@ROHITKUMAR-mu7ik 3 жыл бұрын
the perfect time you made a video for me thanks a lot.
@haile3619
@haile3619 8 ай бұрын
Shortest and best explanation ever!!! Thank you bro!
@python-for-everyone
@python-for-everyone 8 ай бұрын
You are welcome!
@GiangNguyenTruong-oh7qp
@GiangNguyenTruong-oh7qp 8 ай бұрын
Thank you so much it helps me a lot. It so clearly. I try to find many places to get it. but only you vid helps me
@python-for-everyone
@python-for-everyone 8 ай бұрын
Happy to help
@Sufailps
@Sufailps Жыл бұрын
The best explanation ever
@danielj.7656
@danielj.7656 2 жыл бұрын
Explanation helps a lot, and was easier to understand for me than other videos. Thank you
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thank you. That is a great compliment!
@pratikrajpandey
@pratikrajpandey 2 жыл бұрын
excellent video.. love it ... please keep making these videos...
@pacificlite
@pacificlite Жыл бұрын
Man, This is so clearly explained. Unreal!
@python-for-everyone
@python-for-everyone Жыл бұрын
Thanks for the compliment!
@mauricioacuna3746
@mauricioacuna3746 2 жыл бұрын
Just subscribed to this channel so far the explanations are awesome please keep up the good work regards from Chile !
@danielduran5969
@danielduran5969 2 жыл бұрын
you are really great, thanks for the explanation :)
@saniasiddiquieast
@saniasiddiquieast Ай бұрын
Thumbnail was the reason I clicked this video because I had the same feeling for self as the person in thumbnail had😂
@python-for-everyone
@python-for-everyone Ай бұрын
I think we've all been there :-). Was the video helpful?
@cesco24tv17
@cesco24tv17 Жыл бұрын
well done! Looked for an answer all over google but this straight forward tutorial is the best explanations I found! 😄
@bryanurizar
@bryanurizar Жыл бұрын
Holy fuck! Finally a video that explains self properly and in a couple of minutes! Love how you walked through the execution! Thank you!
@python-for-everyone
@python-for-everyone Жыл бұрын
You are welcome. Glad it helped you.
@greenapetranslord4870
@greenapetranslord4870 2 жыл бұрын
Thank you for keeping it simple and short.
@kobruh9642
@kobruh9642 2 жыл бұрын
finally someone is explaining it finally!
@pallavkan
@pallavkan Жыл бұрын
finally I understood after lot of videos!!! that really make sense now!
@python-for-everyone
@python-for-everyone Жыл бұрын
Thanks for the compliment!
@amalkrishnas1696
@amalkrishnas1696 Жыл бұрын
very simple and easy to understand, thanks for the video
@HimanshuSingh-xk9od
@HimanshuSingh-xk9od 3 жыл бұрын
Clear and Crisp explanation, probably the best one..!! If I can please request the content creator to do a video on Kivy ( self, root , app)
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thanks, I would like to do a video on GUI frameworks but it has to wait as I am working on a Neural-Network-from-scratch course. And it is more work than I expected.
@andrewvalenski921
@andrewvalenski921 Жыл бұрын
This is a beautifully simple and intuitive explanation - great video! Subbed!
@python-for-everyone
@python-for-everyone Жыл бұрын
Thanks for the kind words!
@juancruz151
@juancruz151 2 жыл бұрын
what a legend, best explanation ever! Thanks
@python-for-everyone
@python-for-everyone Жыл бұрын
Wow, thanks!
@JeganSriragavan28
@JeganSriragavan28 3 жыл бұрын
Great video..please continue to do more object oriented programming in python...
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thanks. Each month, I give away 10 of my OO for Python courses on Udemy. Here is a free link you (or anyone else who reads this) can use. www.udemy.com/course/learn-object-oriented-programming-with-python/?couponCode=KZbin
@Debelinka
@Debelinka 10 ай бұрын
Thanks and once again big thanks! Like
@training7574
@training7574 Жыл бұрын
Very helpful, thanks.
@python-for-everyone
@python-for-everyone Жыл бұрын
Glad it was helpful!
@msteele919
@msteele919 Жыл бұрын
May you be blessed by all of the different gods 😇 Life saver!
@python-for-everyone
@python-for-everyone Жыл бұрын
Thank you very much for that nice wish!
@MrDaoJones
@MrDaoJones 10 ай бұрын
I finally understand.
@clemeverett4173
@clemeverett4173 2 жыл бұрын
that was fantascticly useful. Thanks mate
@mohamedashrafnk
@mohamedashrafnk 3 жыл бұрын
Very nice explanation, thank you ..
@python-for-everyone
@python-for-everyone 3 жыл бұрын
Thanks for the compliment!
@himanshu4807
@himanshu4807 2 жыл бұрын
nice bro....perfect...just perfect...this channel will go far
@python-for-everyone
@python-for-everyone 2 жыл бұрын
That is so kind of you to say. Thanks!
@memereview8149
@memereview8149 8 ай бұрын
great video! thx
@tj1486
@tj1486 5 ай бұрын
You're the best.
@shawnkhoo1949
@shawnkhoo1949 3 жыл бұрын
Super clear explanation and simple yet straightforward illustrations. You deserve a like!
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thank you very much!
@souravendra
@souravendra 2 жыл бұрын
glorious explanation. thank you so much!
@mcaddit6802
@mcaddit6802 8 ай бұрын
Thanks man!!!
@user-xz7mu1jw3p
@user-xz7mu1jw3p Жыл бұрын
really appreciate this explanation😀
@J-K-AG
@J-K-AG 2 ай бұрын
Great video now i understand what self is after yrs of search. However, when do you not use self? I am not an expert in python so please forgive my ignorance
@python-for-everyone
@python-for-everyone 2 ай бұрын
To see when to use self and when not, watch this video next: kzbin.info/www/bejne/p4mYhaN4r9V8rdE
@haameemshimar8828
@haameemshimar8828 Жыл бұрын
Thank you so much that was really a great explanation ever
@MiBaLinuxTech
@MiBaLinuxTech 10 ай бұрын
Thanks a lot for this explanation
@martinlancaster5109
@martinlancaster5109 2 жыл бұрын
eureka! thank you!
@Bubblecoffee
@Bubblecoffee 2 жыл бұрын
Thanks for this
@python-for-everyone
@python-for-everyone Жыл бұрын
Any time
@esoopthederp7672
@esoopthederp7672 Жыл бұрын
Took me two watches but it’s clicked, thanks!
@python-for-everyone
@python-for-everyone Жыл бұрын
Good to hear!
@Rikki-xj7gv
@Rikki-xj7gv 4 ай бұрын
thank you so much for work
@python-for-everyone
@python-for-everyone 4 ай бұрын
You're welcome!
@samvid1992
@samvid1992 3 жыл бұрын
thank you very much. awesome explanation.
@matheussoares4281
@matheussoares4281 2 жыл бұрын
JESUS, ISSO ESTÁ TÃO BEM EXPLICADO QUE MESMO EU NÃO FALANDO INGLÊS EU ENTENDI 100%. DEUS TE ABENÇOE!!!!!!
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Muito obrigado!
@MemasMaklas
@MemasMaklas Жыл бұрын
Really good explanation!!!
@rudravaramsharan5351
@rudravaramsharan5351 Жыл бұрын
Thanks bro
@Rudra-go6us
@Rudra-go6us 3 жыл бұрын
very clear. Thank You
@tutoro5567
@tutoro5567 Жыл бұрын
ooooooo that what it is, thank you
@sashwattanay
@sashwattanay 2 жыл бұрын
Thank you so much.
@adrianayon5513
@adrianayon5513 2 жыл бұрын
I understand what its doing but why does it work?? Also, I feel like self = e but nobody says it.
@MCSGproject
@MCSGproject 2 жыл бұрын
Why isn't self implied then? what would happen if you didn't have self?
@elektro8174
@elektro8174 2 жыл бұрын
thx
@thereisnoname2052
@thereisnoname2052 Жыл бұрын
I think if you translate this video into many languages, it will be useful to many people
@bubblebath2892
@bubblebath2892 5 ай бұрын
How do i print the name of the object when it is created - i.e how to print(e)...coz print(self) gives a location not 'e'
@python-for-everyone
@python-for-everyone 5 ай бұрын
The object has no name. But if you mean a name attribute, then add this method to the class: def __str__(self): return self.name
@abhishektyagi4428
@abhishektyagi4428 2 жыл бұрын
thanks a lot dope explanation
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thank you!
@zoshida
@zoshida 2 жыл бұрын
nice
@Misc_useful
@Misc_useful 3 жыл бұрын
Very nice explanation. I subscribed to your KZbin channel
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thanks!
@bg6159
@bg6159 Жыл бұрын
Thanks for explanation But in Python Class fields and properties definition it's not clear like in C# and Java. self.salary is look like local variable, but in Python is used like public global variable.
@python-for-everyone
@python-for-everyone Жыл бұрын
I agree that C# makes it more clear. However, self.salary is an attribute, not a global variable.
@bunny.bunbob
@bunny.bunbob 2 жыл бұрын
decent, but gets quite lost after 1:20
@olagarto1917
@olagarto1917 4 ай бұрын
why calling the instance wont make it explicit that you are calling int?
@python-for-everyone
@python-for-everyone 4 ай бұрын
That is the way Python implemented the mechanism.
@luudest
@luudest Жыл бұрын
Stupid question: Is „self“ always used when working with classes or are there examples where „self“ is better not be used (and why)?
@python-for-everyone
@python-for-everyone Жыл бұрын
Yes there are examples of class methods that do not use self. Class methods get cls (the class object) as first parameter and static methods get no additional first parameter at all.
@luudest
@luudest Жыл бұрын
@@python-for-everyone thx. Just read about self and cls. Followup question: Is it right that neither of them are keywords in python? „They are just ideal naming conventions whose name can be changed and yet the functionality would be the same“
@python-for-everyone
@python-for-everyone Жыл бұрын
@@luudest Your assumption is true. cls and self are conventions. I show this in a follow up video: kzbin.info/www/bejne/p4mYhaN4r9V8rdE
@user-cl7sk9mc3w
@user-cl7sk9mc3w Жыл бұрын
def set_salary isn;t attribute but method ?? and self.salary is attribute ? confusing ...
@python-for-everyone
@python-for-everyone Жыл бұрын
It is a bit different. def set_salary is a function in the class that becomes a bound method when it is retrieved via attribute set_salary. If you want to dive in a bit deeper, watch this next: kzbin.info/www/bejne/rmXNZ5Wwl8eraNE
@rockstarprashantpanth1545
@rockstarprashantpanth1545 2 жыл бұрын
What is caller at 1:55
@python-for-everyone
@python-for-everyone 2 жыл бұрын
The thing/user/code that calls the function.
@raghuraman8829
@raghuraman8829 3 жыл бұрын
That was great ! i feel really bad when i noticed likes ...
@python-for-everyone
@python-for-everyone 2 жыл бұрын
Thank you for the compliment!
@manickam7231
@manickam7231 Жыл бұрын
Then y we will be nt using this in jaba
@python-for-everyone
@python-for-everyone Жыл бұрын
No, Jaba does it implicitly
@116sharan.d.k6
@116sharan.d.k6 Жыл бұрын
Why self. Salary =num
@frozeneye100
@frozeneye100 Ай бұрын
Mine goes salary.num() TypeError: please consult with HR about your instance…
@Lynn-ds2qj
@Lynn-ds2qj 2 жыл бұрын
I still don't get it...at all
@Pandabubble
@Pandabubble Жыл бұрын
You sir, are A MAY ZING.
@Arcann_bhp
@Arcann_bhp Жыл бұрын
If someone would sit there and draw arrows around while explaining a code, I’d be a programmer in 2 min WTF
@proproductreview6892
@proproductreview6892 2 жыл бұрын
wish you had subtitle
@rohanofelvenpower5566
@rohanofelvenpower5566 2 жыл бұрын
YES, I watched like 5 other videos on this and long ones but it just didn't click the e refers to the self!!!
@walterstraub150
@walterstraub150 9 ай бұрын
I still don't get it :^) but thanks
@python-for-everyone
@python-for-everyone 9 ай бұрын
It took me a while to get it either. Here is an updated video that might help you further: kzbin.info/www/bejne/rmXNZ5Wwl8eraNE
@serious6037
@serious6037 3 жыл бұрын
you are god.
@DigitalHandle
@DigitalHandle Жыл бұрын
My guy dumbed down the explanation yet i still don't understand, you gotta super duper dumb down this stuff before i start understanding it
@surprisedpikachu4716
@surprisedpikachu4716 2 жыл бұрын
Bruhh it was that simple, BRUHHHHHHHHHHHHHHHHHH!
@python-for-everyone
@python-for-everyone Жыл бұрын
Once you see it, you go Bruhh :-)
@gokulvenkatesan5798
@gokulvenkatesan5798 3 жыл бұрын
Sappu
@AceThePeasant
@AceThePeasant Жыл бұрын
E
@python-for-everyone
@python-for-everyone Жыл бұрын
Take a deep dive into self in Python by learning bound methods: kzbin.info/www/bejne/rmXNZ5Wwl8eraNE
@heuristicalgorithm8465
@heuristicalgorithm8465 2 жыл бұрын
makes no sense
@neuzen
@neuzen 3 жыл бұрын
Poor language design? Other languages don't need such nonsense.
@Lexyvil
@Lexyvil 2 жыл бұрын
I agree. In C#, "self" is not required, and functions do the same thing.
@vitalii200
@vitalii200 Жыл бұрын
Hate python. Have 7 years of exp in Java
@python-for-everyone
@python-for-everyone Жыл бұрын
Coming from C# myself, I can imagine Python being strange at first. But if I can help you, just let me know.
@JasimGamer
@JasimGamer Жыл бұрын
we don't need to type "self" we can name it anything but the common is "self" we could do this def __init__(this,arg): this.a = arg
@joeking5211
@joeking5211 Жыл бұрын
so are you saying that you could change it for anything like def __init__(whywouldanyonecreatingalangugemakeitsocrypticandconfusing,arg): whywouldanyonecreatingalangugemakeitsocrypticandconfusing.a = arg ??????
@dadecky5276
@dadecky5276 Жыл бұрын
thanks man, really helpful
@python-for-everyone
@python-for-everyone Жыл бұрын
Glad it helped!
Polymorphism in Python
4:39
Python for Everyone
Рет қаралды 5 М.
Difference between function and method in Python. Is it just self?
7:48
Python for Everyone
Рет қаралды 7 М.
Schoolboy Runaway в реальной жизни🤣@onLI_gAmeS
00:31
МишАня
Рет қаралды 3,7 МЛН
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00
wow so cute 🥰
00:20
dednahype
Рет қаралды 29 МЛН
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 58 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 802 М.
OOP Class Inheritance and Private Class Members - Python for Beginners!
16:12
How bound methods are the key to understanding SELF in Python.
6:09
Python for Everyone
Рет қаралды 2,2 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 397 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 504 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 265 М.