Python class init function
<p>When I init a class in python, is it only called once? For example, if I write an if statement in the init area. </p>

<pre><code>class hi():
    def __init__():
        # bla bla bla
</code></pre>

<p>Does it only loop over once?</p>

<p><code>__init__</code> is the constructor of the class. It is called once for every instance of the class you create.</p>

<pre><code>class A(object):
    def __init__(self):
        print('__init__ called')

a1 = A()  # prints: __init__ called
a2 = A()  # prints: __init__ called
</code></pre>

<p>BTW, this is not something specific to pygame, but python in general.</p>

<p>The constructor always takes at least one argument: <code>self</code>. It can take additional arguments. <code>self</code> is the instance which is being constructed and you can write initialization of it in the constructor.</p>

<pre><code>class A(object):
    def __init__(self, value):
        self.value = value

a1 = A(17)

print (a1.value) # prints: 17
</code></pre>

python class