Answer the question
In order to leave comments, you need to log in
Python. When to pass parameters to a class?
I'm learning Python in conjunction with Kivy.
Got a question. Although, I understand that it is more general and has little to do with kiwi.
Is there a difference when to specify the parameters of the created class instances: when creating an instance or later, through properties. Perhaps I'm still confused in terminology, it will be clearer in the code. For example, I create a button with parameters in two ways - both seem to work.
Is there a fundamental difference? The second way seems more attractive because of the IDE hints, although it takes more lines.
button = Button(text='Hello world', font_size=14, background_color=[.5, 0, 0,0])
layout.add_widget(button )
button = Button()
button.text='Hello world'
button.font_size=14
button.background_color=[.5, 0, 0,0]
layout.add_widget(button )
Answer the question
In order to leave comments, you need to log in
in the first option, you initialize with already given values, and in the second, you initialize with an empty one, and then you replace the empty values with the desired ones
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question