-1

I am new in python, and I would like to know what is the purpose of the __init__(self,Name1,Name2,...) inside a class.

sloth
  • 99,095
  • 21
  • 171
  • 219
tcassanelli
  • 175
  • 8
  • 2
    This is extensively documented in the official python tutorial, as well as in every other tutorial that deals with classes in python. Also, the duplicate question linked by Dominic is the first google result for both the queries `python init` and `python __init__`. Please invest some effort into searching an answer yourself before asking a quesiton. – l4mpi Feb 26 '14 at 11:39

1 Answers1

2

It's the initializer for an instance of the class. self refers to the object itself while Name1,Name2 etc are input parameters to the initializer.

class Thingy(object):
    def __init__(self, color):
        self.color = color


x = Thingy('red')
print x.color
'red'
Lorcan O'Neill
  • 3,303
  • 1
  • 25
  • 24