About Python Class and methods

Hi forum! i didnt know where to post in this forum, so well… i posted here.

Can anyone help me with a few questions on python?
Im studying with a book, but the book doesnt explain a few things… Since im a java programmer, im obviously trying to see the differences between the two languages and i know python can be procedural language too… Anyway, can anyone help me with this simple code?


class Application():

    #THis is the constructor?
    #Why it receives self?
    def __init__(self):
        print "__init__"

    #Why it receives self?
    def printText(self, text):
        print text


class Example():
    def run(self):
        print "Hello, world!"





a = Application()
#Why i dont need to pass, 'a" as a first parameter
a.printText("Hi World")


# i Dont get this :
if __name__ == '__main__':
    Example().run()

http://www.tutorialspoint.com/python/python_classes_objects.htm

self is called this in java, where it is normally an implicit argument, but is explicit in method declarations in python.

if __name__ == '__main__': is querying the interpreter if this file is being run as the main program.
Basically a public static void main in java, but more of a question than a statement.

Hm, i see.
And well, why is “self” required? it doesnt make sense to me ‘-’

Some languages simply have it explicit.

It seems weird when you’re used to an implicit ‘this’ pointer, but if you think about it, a magical invisible 1st-argument-to-every-function-on-an-instance is a bit weird too.
But then python (and others) are a little inconsistent (albeit for ergonomic purposes) by having the call syntax as instance.function(args) instead of function(instance, args) a la C.