What is self in Python?

  Рет қаралды 23,373

Python Morsels

Python Morsels

Күн бұрын

Python's "self" is really just a variable that points to the current instance of our class. Every method you define must accept "self" as its first argument.
Read an article version of this video at pym.dev/what-is-self/
Find more Python screencasts at pym.dev/screencasts/
00:00 A Python class with self in each method
00:28 Do we need that self argument?
01:22 What is self?
02:26 But what does self mean? Could we rename it?
03:10 Recap: self is the first method of every Python class
#python #oop

Пікірлер: 45
@saluberis
@saluberis 3 ай бұрын
Add "Python ASMR" to the video title
@wisdomlounge4452
@wisdomlounge4452 Ай бұрын
Wow! And I was about to comment about how this guy's voice has a perfect tone for ASMR, lol!
@daved8698
@daved8698 Ай бұрын
the logo "GIRLS" in front of the Tshirt
@malakhassan9816
@malakhassan9816 25 күн бұрын
Yes
@InfoSecGSO
@InfoSecGSO 21 күн бұрын
Thank you. Well explained. Subbed.
@techrazor3280
@techrazor3280 13 күн бұрын
Can you lower the audio? Its very loud.
@SoniaChavez-je7hq
@SoniaChavez-je7hq 3 ай бұрын
Very interesting and helpful explanation. You are an excellent teacher. Good work !
@PythonMorsels
@PythonMorsels 3 ай бұрын
Thank you! 😊
@abuali5513
@abuali5513 3 ай бұрын
I like your calm voice. Thanks 🙏
@mathewmcfool
@mathewmcfool 3 ай бұрын
Thanks, u da man!
@ACCESSZERO1
@ACCESSZERO1 3 ай бұрын
People here complaining about you being too silent, bug frankly it like it, its nice and soothing ✌🏻
@Code4Life400
@Code4Life400 3 ай бұрын
I thought there was a problem with my hearing aid 😂
@techrazor3280
@techrazor3280 13 күн бұрын
No!! He is extremely loud. My eardrums are exploding. 📢🔊🔊
@hudatolah
@hudatolah 2 ай бұрын
I like the short content. I also like “this” better because I am already used to that from C++ 😂
@vorfreu
@vorfreu 6 ай бұрын
too silent, you can make the video a bit louder
@ichoudhury007
@ichoudhury007 5 ай бұрын
I think sometime soft soothing voice can be more effective at honing the lesson better than being loud and rambunctious :)
@Thekingslayer-ig5se
@Thekingslayer-ig5se 20 күн бұрын
@@ichoudhury007it’s good but at times it’s sleepy 😊
@itsomarka
@itsomarka 3 ай бұрын
cool stuff, but why are u whispering ?
@PythonMorsels
@PythonMorsels 3 ай бұрын
For more on Python's classes, see this playlist: kzfaq.info/get/bejne/ra-hZtyKp6u-h4U.html There's also a text-based version of each of those videos at www.pythonmorsels.com/articles/class/ And for practice making your own class, try out this Python Morsels exercise: www.pythonmorsels.com/exercises/7b02e2aae0634dc4a6f8cec15d1e1a8a/?level=beginner
@chrishabgood8900
@chrishabgood8900 2 ай бұрын
This is why I prefer ruby. Self is the instance, no need to pass it around.
@PythonMorsels
@PythonMorsels 2 ай бұрын
As a method caller, we don't actually need to pass it around because Python does the "passing" part for us. But as a method definer, we do need to accept it as an argument which will be passed in. That's not to say Python's style is better though...it definitely takes some adjusting to get used to that passed-in self!
@yoavmor9002
@yoavmor9002 5 ай бұрын
Yet another Python quirk that becomes IMMEDIATELY simpler when you write a bit of C. There is no such thing as a function that can magically access some local variable. For the function to have access to the data of the object, the object must be passed into the function. That is self.
@yoavmor9002
@yoavmor9002 3 ай бұрын
@@considerallthat3310 nah but I am studying computer engineering abroad and studying C really cleared up a lot of stuff
@akashbharadwaj1
@akashbharadwaj1 3 ай бұрын
@@yoavmor9002 awesome explanation man... really great.. so can we have different words for each instance? like can we have self in one method..... this in other method... or xyz in another method..... can we have different ones in each? i am not asking about best coding pracitces.. i am asking CAN we do it? can it be done?
@akashbharadwaj1
@akashbharadwaj1 3 ай бұрын
i want to add that your comment made the video meaningful to be very honest. i read your comment and watched again.. and everything was so clear .. thank you sooo sooo much. really. god bless you thanks
@yoavmor9002
@yoavmor9002 3 ай бұрын
@@akashbharadwaj1 Yeah it's possible, all it is is a name for a parameter. You can call it self in the __init__ function, call it stringable in the __repr__ function and call it this_object in a func function
@KW-jj9uy
@KW-jj9uy 3 ай бұрын
Still, it makes the syntax look gross..... self everwyere as a hidden 1st variable to function...
@shanmugaraj4416
@shanmugaraj4416 19 күн бұрын
"pyladies", "django girls"
@akashbharadwaj1
@akashbharadwaj1 3 ай бұрын
awesome explanation man... really great.. so can we have different words for each instance? like can we have self in one method..... this in other method... or xyz in another method..... can we have different ones in each? i am not asking about best coding pracitces.. i am asking CAN we do it? can it be done?
@PythonMorsels
@PythonMorsels 2 ай бұрын
Absolutely! 👍 You CAN though of course you shoudn't. Here's an example: pym.dev/p/2cn9c/
@hw_was_taken423
@hw_was_taken423 4 ай бұрын
thanks for the guide but bro are you good? You look like you haven't slept in days
@thomasstien2134
@thomasstien2134 4 ай бұрын
I think bro might just be faded
@wisdomlounge4452
@wisdomlounge4452 Ай бұрын
Ironically, his voice has that perfect ASMR pitch that, while apparently not getting enough nightly rest, he can easily talk others into getting the kind of profoundly deep sleep that he himself needs!
@derciferreira2523
@derciferreira2523 3 ай бұрын
Are hungry?
@AkshaySharma-vm9sp
@AkshaySharma-vm9sp 3 ай бұрын
kindly use good mic, your voice is too low
@wisdomlounge4452
@wisdomlounge4452 Ай бұрын
Don't encourage him! His current mic set up gives his voice a perfect ASMR quality. This video helps treat insomnia, lol!👍
@daddyddesign
@daddyddesign 6 ай бұрын
Why are you whispering.
@penguinwizard
@penguinwizard 5 ай бұрын
Don't attack people personally, you could have rephrased that comment as "The sound is very low, and I am having issues hearing. Please fix."
@renatooliveira0266
@renatooliveira0266 5 ай бұрын
​@penguinwizard I disagree with you. The guy is in fact, whispering. Why should we call it otherwise?
@rubyciide5542
@rubyciide5542 5 ай бұрын
@@penguinwizard why tf is he whispering?
@IronShredder
@IronShredder 4 ай бұрын
Who cares? It's better than being loud as hell for no reason like a lot of content creators are nowadays
@megsman4749
@megsman4749 4 ай бұрын
There probably should have been a disclaimer. Like ‘I live in a studio apartment with room mates who are sleeping.’ Or something. But that’s just me.
@AlexandreFerreira-jb2jl
@AlexandreFerreira-jb2jl 2 ай бұрын
Self refers to the objects that are created within the class. Self==class object.
@PythonMorsels
@PythonMorsels 2 ай бұрын
Yup! That's a good way to explain it. 👍
Python's __repr__ and __str__
3:28
Python Morsels
Рет қаралды 7 М.
Is THIS Python's MOST Underrated Operator? (Walrus Operator)
5:45
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 3,6 МЛН
Тяжелые будни жены
00:46
К-Media
Рет қаралды 5 МЛН
ISSEI funny story😂😂😂Strange World | Magic Lips💋
00:36
ISSEI / いっせい
Рет қаралды 193 МЛН
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 83 М.
Understanding *args And **kwargs In Python || Born2Code
5:11
Born2Code
Рет қаралды 2,6 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 236 М.
What is "self" in Python?
2:23
Python for Everyone
Рет қаралды 98 М.
Why __init__.py File is Used in Python Projects | 2MinutesPy
2:40
#49 Python Tutorial for Beginners | Class and Object
11:01
Telusko
Рет қаралды 796 М.
For loops in Python are easy 🔁
5:06
Bro Code
Рет қаралды 235 М.
Assignment Operators in Python
9:41
Neso Academy
Рет қаралды 24 М.
Which Phone Unlock Code Will You Choose? 🤔️
0:14
Game9bit
Рет қаралды 11 МЛН
How charged your battery?
0:14
V.A. show / Магика
Рет қаралды 2,2 МЛН
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 4,4 МЛН
Apple iPhone 15 Pro Max With Smallrig Professional Photography kit #shorts
0:14