-2
I was doing a Dice in python3, so far so good. but I don’t understand why I need to put the attributes in init, being that having them or not will work in the "same way" and I can’t see a "sense".
I learned Object Orientation with Java and there really things make more sense or I’m not understanding. Python’s Object Orientation is a bit confusing for me.
I’m sorry for the way I’m expressing/writing, maybe it sounds gross.
class Dado(object):
def __init__(self, cor="vermelho", lado=6):
self._cor = cor
def setCor(self, cor):
self._cor = cor
def getCor(self):
return self._cor
or
class Dado(object):
def __init__(self):
pass
def setCor(self, cor):
self._cor = cor
def getCor(self):
return self._cor
Why do I need to declare an attribute in init? or why this is necessary?
Like, it works both ways.
What is the doubt?
– Danizavtz
Why do I need to declare an attribute in init? or why this is necessary? Type, works in both ways.
– João Vítor
This answers your question? Why do we have to use the self attribute as an argument in the methods?
– hkotsubo