I am fairly new to learning programming and starting with Python. I have read on the utility of using init() function in classes and understand it somewhat. However, I am still a little confused and hope someone could clarify that.
So I have two set of preliminary codes which give the same output, but one uses init(). The first one is as follows:
class person:
def who(self, name):
print('I am', name)
name=str('Joe')
person().who(name)
The second one is here:
class person:
def __init__(self, name):
self.name = name
def who(self):
print('I am', self.name)
p = person('Joe')
p.who()
My basic question is what would I miss in general case of my code (may be more complex at some stage) if I take the first approach and not the second one Or what I would I gain with the second approach.
Thanks!
PS: My question is not what init() means (although that is related and certainly of interest to me), but why making use of init() essentially makes the code better.