Тёмный

What is self in Python? 

Python Morsels
Подписаться 3,4 тыс.
Просмотров 23 тыс.
50% 1

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

Наука

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

 

3 июн 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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 Месяц назад
Yes
@InfoSecGSO
@InfoSecGSO 26 дней назад
Thank you. Well explained. Subbed.
@SoniaChavez-je7hq
@SoniaChavez-je7hq 3 месяца назад
Very interesting and helpful explanation. You are an excellent teacher. Good work !
@PythonMorsels
@PythonMorsels 3 месяца назад
Thank you! 😊
@techrazor3280
@techrazor3280 18 дней назад
Can you lower the audio? Its very loud.
@abuali5513
@abuali5513 3 месяца назад
I like your calm voice. Thanks 🙏
@mathewmcfool
@mathewmcfool 3 месяца назад
Thanks, u da man!
@ACCESSZERO1
@ACCESSZERO1 4 месяца назад
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 18 дней назад
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 25 дней назад
@@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-wIq3yYBEZWQ.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!
@shanmugaraj4416
@shanmugaraj4416 24 дня назад
"pyladies", "django girls"
@KW-jj9uy
@KW-jj9uy 4 месяца назад
Still, it makes the syntax look gross..... self everwyere as a hidden 1st variable to function...
@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 3 месяца назад
Absolutely! 👍 You CAN though of course you shoudn't. Here's an example: pym.dev/p/2cn9c/
@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
@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!👍
@derciferreira2523
@derciferreira2523 3 месяца назад
Are hungry?
@hw_was_taken423
@hw_was_taken423 5 месяцев назад
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!
@daddyddesign
@daddyddesign 6 месяцев назад
Why are you whispering.
@penguinwizard
@penguinwizard 6 месяцев назад
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
Просмотров 7 тыс.
What is "self" in Python?
2:23
Просмотров 98 тыс.
5 Good Python Habits
17:35
Просмотров 345 тыс.
Variables are pointers in Python
3:12
Просмотров 465
How To Create Decorator Functions In Python
4:59
Просмотров 1,5 тыс.
10 Python Comprehensions You SHOULD Be Using
21:35
Просмотров 105 тыс.
What is `self` in Python?
4:15
Просмотров 38 тыс.
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 789 тыс.
Python Methods and self
13:48
Просмотров 43 тыс.
Python 101: Learn the 5 Must-Know Concepts
20:00
Просмотров 1 млн
Pratik Cat6 kablo soyma
0:15
Просмотров 8 млн
КАК GOOGLE УКРАЛ ANDROID?
17:44
Просмотров 87 тыс.