I started learning python (with no prior knowledge of it, not programming) few weeks ago and am stuck at Classes. Currently the "init" class method confuses me. What does it do, in fact?
Here is an example of the init method usage I am copying from particular python book:
class Person:
def __init__(self, name):
self.name = name
def sayHi(self):
print "Hello, my name is", self.name
p = Person("George")
p.sayHi()
Please do correct me, but the same result could be achieved without the _init method, like so:
class Person:
def sayHi(self, name):
print "Hello, my name is", name
p = Person()
p.sayHi("George")
Right?
So what is the purpose of the init method anyway?
Thank you.