No video

What does Python's __init__ method do?

  Рет қаралды 33,095

Python and Pandas with Reuven Lerner

Python and Pandas with Reuven Lerner

Күн бұрын

If you are creating a new class in Python, you're probably writing a new _init_ method. But what does _init_ do? And do you really need to write it? In this video, I answer a question from Brett, who has read my book (PythonWorkout....) and subscribes to my newsletter (BetterDevelope....
(And apologies for the cut-off sound at the start of the video!)

Пікірлер: 52
@studentHindes
@studentHindes Жыл бұрын
Your typing skills are otherworldly. Oh, and I really like your teaching style! Edit: I just subscribed to manning to read your book - what a cool platform
@ReuvenLerner
@ReuvenLerner Жыл бұрын
Excellent and thanks on all fronts!
@smashies118
@smashies118 7 ай бұрын
This video just prevented me from going down a rabbit hole. Thanks!
@ReuvenLerner
@ReuvenLerner 7 ай бұрын
Delighted to hear it!
@safkaify7875
@safkaify7875 3 ай бұрын
Nicely explained. Keep up the good work.
@ReuvenLerner
@ReuvenLerner 3 ай бұрын
My pleasure; glad you enjoyed!
@basil9633
@basil9633 2 ай бұрын
Great video ! , videos like this are very informative and help young developers like me.
@ReuvenLerner
@ReuvenLerner 2 ай бұрын
I'm so glad to hear it helped!
@o1Lars
@o1Lars 7 ай бұрын
Thanks also for saying "dunder init", as it just helps tons to know the correct wording when talking about code !
@ReuvenLerner
@ReuvenLerner 7 ай бұрын
Glad it helped!
@muntadher8087
@muntadher8087 2 жыл бұрын
Thank you so Much for having the live read online reading, it's useful. I will start reading your book. God bless you! Thank you
@ReuvenLerner
@ReuvenLerner 2 жыл бұрын
I'm delighted to hear you enjoyed it, and hope you like the book, too!
@Al-lg8nv
@Al-lg8nv 11 ай бұрын
wow, such a concise explanation. Love your typing speed and accuracy!
@ReuvenLerner
@ReuvenLerner 9 ай бұрын
Thanks so much! The typing speed is all thanks to my father, who forced me to learn to touch type in high school. It was definitely one of the best skills I ever learned.
@bartosz13
@bartosz13 Жыл бұрын
Thank You for this
@ReuvenLerner
@ReuvenLerner Жыл бұрын
Glad it helped!
@Chapter9
@Chapter9 6 ай бұрын
fan of your code typing speed 😀
@ReuvenLerner
@ReuvenLerner 6 ай бұрын
Thanks! It's all thanks to my parents, and especially my father.
@hashimnaushahi
@hashimnaushahi 4 ай бұрын
I really like the way you teach Python! Do you also have a video about the builder pattern, or would you be willing to create one?
@ReuvenLerner
@ReuvenLerner 4 ай бұрын
Thanks for your kind words! I have a (paid, recorded) course on design patterns, but I don't think that it includes the builder pattern. (It often depends on whether I have time to fit it in.) If not, I'll see if I can do something here on KZbin.
@hashimnaushahi
@hashimnaushahi 4 ай бұрын
@@ReuvenLerner Thank you! I'll be looking forward to that video. In the meantime, do you have a link to your paid course?
@ReuvenLerner
@ReuvenLerner 4 ай бұрын
@@hashimnaushahi Absolutely -- the design patterns course is at store.lerner.co.il/design-patterns (which isn't explicitly mentioned yet, but is a free part of my course membership at LernerPython.com). Let me know if you have any further questions!
@bigbadcatbigbcy2933
@bigbadcatbigbcy2933 11 ай бұрын
thank you this explained a lot of things to me
@ReuvenLerner
@ReuvenLerner 11 ай бұрын
I'm so delighted to hear it!
@crystallewis1198
@crystallewis1198 11 ай бұрын
Thank you!
@ReuvenLerner
@ReuvenLerner 11 ай бұрын
My pleasure -- glad it helped!
@manny4527
@manny4527 5 ай бұрын
I wish I could type my code like you. I still have to look at the keyboard 😅
@ReuvenLerner
@ReuvenLerner 5 ай бұрын
Thanks; it's all thanks to my parents! But you can/should also learn to touch type. It's possibly the most practical skill I've ever learned.
@jacques8290
@jacques8290 3 жыл бұрын
Great video, thanks for sharing this.
@vinkenwood8233
@vinkenwood8233 6 ай бұрын
I didn't get it at all, but great video, thanks.
@ReuvenLerner
@ReuvenLerner 6 ай бұрын
Thanks! (Feel free to ask if there are things you still don't understand.)
@SteamTrain2639
@SteamTrain2639 3 ай бұрын
What is the point of the lines that say: self.x = x self.y= y ?
@ReuvenLerner
@ReuvenLerner 3 ай бұрын
Self is the new instance. Attributes set on self are the Python equivalent of setting instance variables. We thus take the parameter x (whose value was set by the caller) and assign it to self.x, keeping the value around. We then do the same thing with y.
@excalizan7697
@excalizan7697 3 жыл бұрын
Great tutorial!
@kdpr007
@kdpr007 3 ай бұрын
Thank you for the video. Ca you please suggest a good book to read on Classes and Objects. Thank you
@ReuvenLerner
@ReuvenLerner 2 ай бұрын
I don't know about a book, but I gave two webinars/courses, "Python objects for newbies," that are part of my subscription service at LernerPython.com . And you can check out my video here, which explains some things: kzbin.info/www/bejne/kHWWnH6BZsSXm7M
@olagarto1917
@olagarto1917 4 ай бұрын
but what is the __init__ doing? i mean, you can just delet it and the code works the same... so what is it actualy duing?
@ReuvenLerner
@ReuvenLerner 4 ай бұрын
__init__ sets attributes on the new instance. If you aren't setting any attributes, then __init__ isn't necessary, and can indeed be removed without consequence. But if you are setting attributes in __init__, then you can't just get rid of it!
@isimbulmakcokolay
@isimbulmakcokolay 3 жыл бұрын
great content, thanks!
@JesseUnderdog
@JesseUnderdog 2 жыл бұрын
Dude, you're good at teaching :P
@ReuvenLerner
@ReuvenLerner 2 жыл бұрын
Thanks so much for the kind words!
@cetilly
@cetilly Жыл бұрын
There is also the __init__.py file, which would be another good topic
@ReuvenLerner
@ReuvenLerner Жыл бұрын
Yes, a good topic to discuss, for sure! Unfortunately, there's no connection between the __init__ method and the __init__.py file, except that both are dealt with at the start of something.
@tarykhai9175
@tarykhai9175 3 жыл бұрын
So much great info, definitely deserved more views!!!
@fusebox9725
@fusebox9725 8 ай бұрын
If the dunder method is used to initialize attributes then what's the use of walrus operator? Btw great video I'm still learning.
@ReuvenLerner
@ReuvenLerner 8 ай бұрын
Glad you enjoyed! The walrus operator is for assignment, just like =, but it is an expression, meaning that it also returns a value. Dunder-init is about assigning values to a new object just after it was created; you could use either = or := to assign those attributes, but the point is convenience, that it happens automatically.
@chriskeo198
@chriskeo198 2 жыл бұрын
can i get a signed copy of that book!
@ReuvenLerner
@ReuvenLerner 2 жыл бұрын
Um.... I've signed a handful at Python conferences, but other than that, or you coming to Israel, I don't really have an easy way to do that, other than sending a copy in the mail.
@dropcloud7114
@dropcloud7114 3 жыл бұрын
Is this w3 school
@ReuvenLerner
@ReuvenLerner 3 жыл бұрын
Nope -- I'm an independent Python trainer, in business since 1995. Welcome to my channel!
@dropcloud7114
@dropcloud7114 3 жыл бұрын
@@ReuvenLerner ok thanks. You teach all python stuff here
@hangout7081
@hangout7081 3 жыл бұрын
@@dropcloud7114 yeah.
Finding substrings in Python
9:46
Python and Pandas with Reuven Lerner
Рет қаралды 3,8 М.
The Joker saves Harley Quinn from drowning!#joker  #shorts
00:34
Untitled Joker
Рет қаралды 72 МЛН
Happy birthday to you by Tsuriki Show
00:12
Tsuriki Show
Рет қаралды 11 МЛН
What is `self` in Python?
4:15
AiCore
Рет қаралды 49 М.
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 349 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 397 М.
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 58 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
Intermediate Python Tutorial: How to Use the __init__.py File
6:22
Eric O Meehan
Рет қаралды 134 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 802 М.
*Args and **Kwargs in Python
3:49
b001
Рет қаралды 268 М.
The Joker saves Harley Quinn from drowning!#joker  #shorts
00:34
Untitled Joker
Рет қаралды 72 МЛН