I need help understanding classes better.
class person:
def sayHi(self):
print('hello world!')
p=person()
p.sayHi()
here what is the use of 'self'?, I've read two tuts on this but don't quite understand fully....
class person:
def _init_(self, name):
self.name=name
def sayHi(self):
print('hello, my name is', self.name)
p=person('rs')
p.sayHi()
And why is _init_ method so special?.
and what are they referring to when they've written 'self.name?'. how does the whole thing above work im at lost completely :-/ .
Under this heading also the author as repeatedly used things like
print('(Initializing {0})'.format(self.name))
print('{0} was the last one.'.format(self.name))
what the heck does {0} do???
could someone please explain this in away a newb can understand:-/
-thank you.