0

Am starting to learn python's classes and objects! I read alone from an ebook. The book has the following example:

class Person:
    def sayHi(self):
        print('Hello, how are you?')

p = Person()
p.sayHi()

# or simplier
Person().sayHi()

I can totally understand the following:

def sayHi():
    print('Hello, how are you?')
sayHi()

However, I have a difficulty understanding the 1st example... Why do I need to use this 'self'? Does the use of 'self' tells python that I can use/call the function sayHi() by calling the class? Other-words, does the 'self' give the right to class Person to react as if it was a function... like passing the rights to the above level?

P.S. Sorry but I am noob in programming and also English is not my mother-lang.. Thanks in advance.

midkin
  • 1,343
  • 1
  • 17
  • 23
  • See http://stackoverflow.com/questions/2709821/python-self-explained – Kaarel Nummert Jun 24 '14 at 18:11
  • Well I 've searched the site before asking the question. However, I don't know anything about @ or end and things like these. Am totally noob in programming, And I would love an easy, definite answer on what am asking, no difficult explanations or 10 sentences of text... :/ – midkin Jun 24 '14 at 18:14
  • 1
    Read all of the answers on that question, not just the selected answer. – OozeMeister Jun 24 '14 at 18:19
  • Maybe it's my English but am having a hard time understanding those answers... – midkin Jun 24 '14 at 18:36

0 Answers0