So I understand how to use init when defining a class in Python. However, I am confused as to what to put inside the init function, or if I should use it at all. For example:
Here I make the user define concept when the class is instantiated:
class Fruit(object):
def __init__(self, concept):
self.concept = concept
But I could also do this, and the user can just change the concept attribute themselves:
class Fruit(object):
def __init__(self):
self.concept = "I am a fruit"
Or I could just abandon the init function altogether:
class Fruit(object):
concept = "I am a fruit"
In each of these examples, I can change the concept attribute as such
test = Fruit()
test.concept = 'Whatever I want'
So I'm not sure why I use the init function in the first place. It seems to only be convenient for defining all the attributes up front.
Moreover, how do I know what to put inside an init function and what to just define outside of the init?