Тёмный

What does Python's __init__ method do? 

Python and Pandas with Reuven Lerner
Подписаться 19 тыс.
Просмотров 33 тыс.
50% 1

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.com/) and subscribes to my newsletter (BetterDevelopersWeekly.com/).
(And apologies for the cut-off sound at the start of the video!)

Наука

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

 

3 окт 2020

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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!
@o1Lars
@o1Lars 6 месяцев назад
Thanks also for saying "dunder init", as it just helps tons to know the correct wording when talking about code !
@ReuvenLerner
@ReuvenLerner 6 месяцев назад
Glad it helped!
@Al-lg8nv
@Al-lg8nv 10 месяцев назад
wow, such a concise explanation. Love your typing speed and accuracy!
@ReuvenLerner
@ReuvenLerner 8 месяцев назад
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.
@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!
@safkaify7875
@safkaify7875 2 месяца назад
Nicely explained. Keep up the good work.
@ReuvenLerner
@ReuvenLerner 2 месяца назад
My pleasure; glad you enjoyed!
@basil9633
@basil9633 Месяц назад
Great video ! , videos like this are very informative and help young developers like me.
@ReuvenLerner
@ReuvenLerner Месяц назад
I'm so glad to hear it helped!
@jacques8290
@jacques8290 3 года назад
Great video, thanks for sharing this.
@isimbulmakcokolay
@isimbulmakcokolay 3 года назад
great content, thanks!
@excalizan7697
@excalizan7697 3 года назад
Great tutorial!
@bartosz13
@bartosz13 Год назад
Thank You for this
@ReuvenLerner
@ReuvenLerner Год назад
Glad it helped!
@bigbadcatbigbcy2933
@bigbadcatbigbcy2933 11 месяцев назад
thank you this explained a lot of things to me
@ReuvenLerner
@ReuvenLerner 11 месяцев назад
I'm so delighted to hear it!
@tarykhai9175
@tarykhai9175 3 года назад
So much great info, definitely deserved more views!!!
@crystallewis1198
@crystallewis1198 11 месяцев назад
Thank you!
@ReuvenLerner
@ReuvenLerner 11 месяцев назад
My pleasure -- glad it helped!
@kdpr007
@kdpr007 2 месяца назад
Thank you for the video. Ca you please suggest a good book to read on Classes and Objects. Thank you
@ReuvenLerner
@ReuvenLerner Месяц назад
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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ZD3kKK1_deQ.html
@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.
@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.
@olagarto1917
@olagarto1917 3 месяца назад
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 3 месяца назад
__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!
@Chapter9
@Chapter9 5 месяцев назад
fan of your code typing speed 😀
@ReuvenLerner
@ReuvenLerner 5 месяцев назад
Thanks! It's all thanks to my parents, and especially my father.
@JesseUnderdog
@JesseUnderdog 2 года назад
Dude, you're good at teaching :P
@ReuvenLerner
@ReuvenLerner 2 года назад
Thanks so much for the kind words!
@hashimnaushahi
@hashimnaushahi 3 месяца назад
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 3 месяца назад
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 RU-vid.
@hashimnaushahi
@hashimnaushahi 3 месяца назад
@@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 3 месяца назад
@@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!
@vinkenwood8233
@vinkenwood8233 5 месяцев назад
I didn't get it at all, but great video, thanks.
@ReuvenLerner
@ReuvenLerner 5 месяцев назад
Thanks! (Feel free to ask if there are things you still don't understand.)
@manny4527
@manny4527 4 месяца назад
I wish I could type my code like you. I still have to look at the keyboard 😅
@ReuvenLerner
@ReuvenLerner 4 месяца назад
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.
@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.
@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
Просмотров 3,8 тыс.
A simple explanation of super() in Python
15:02
Просмотров 47 тыс.
ПОМОГЛА НАЗЫВАЕТСЯ😂
00:20
Просмотров 1,4 млн
Python Tutorial: if __name__ == '__main__'
8:43
Просмотров 2 млн
What is `self` in Python?
4:15
Просмотров 46 тыс.
Learn Any Programming Language In 3 Hours!
22:37
Просмотров 307 тыс.
What is Python's Main Function Useful For?
8:08
Просмотров 75 тыс.
Functions vs Classes: When to Use Which and Why?
10:49
Просмотров 149 тыс.
Nokia 3310 top
0:20
Просмотров 4,2 млн