0

Where is it better to declare the class members in Python if I'm not going to initialize them through parameters? In __init__ or just under the Class declaration?

Ex:

class A():

    def __init__(self):
        self.__variable = 0

class B():
     __variable = 0

And if I went to initialize some and not the others? Is it better to put all in __init__ or just the ones that are going to be initialized through parameters?

Ex:

class A():

    __variable1 = 0

    def __init__(self, variable2):
        self.__variable2 = variable2

class B():

        def __init__(self, variable2):
            self.__variable1 = 0
            self.__variable2 = variable2

Justify your answers please.

Cheers and thanks.

Wrong
  • 1,195
  • 2
  • 14
  • 38

0 Answers0