0
The __init__ magic method arguments
Hello everyone, I'm learning Python and currently trying to embrace the OOP section. Can someone please explain how it affects my created class, if I don't state the arguments I use in the brackets in the headline right after "__init__"? Here's some example. https://code.sololearn.com/c65cXcwCAGgS/?ref=app
7 ответов
+ 1
That means you are creating three variables, right when the class is created
+ 1
those are not arguments
0
__init__ is a constructor for a class, meaning that whenever an instance of that class is created, that function is called right away
0
Every __init__ definition must have “self” as an argument or it won’t be associated with the class
0
Okay, but what about the line 3 in the example code: def __init__(self):
I don't put any arguments in the brackets except for 'self'. Yet I can still use them as usual. What difference it makes when I do state them and when I do not?
Except for 'self', I have there '_desc', 'class_name', 'health'.
0
So this also means that I set new values for them each time I create new object. Thank you man! I think I understood it now.
0
Yup!