title: Class instantiation and 'self' in python
body: <p>I know a ton has been written on this subject.  I cannot, however, absorb much of it.  Perhaps because I'm a complete novice teaching myself without the benefit of any training in computer science.  Regardless, maybe if some of you big brains chime in on this specific example, you'll help other beginners like me.</p>
  
  <p>So, I've written the following function which works just fine when I call it (as a module?) as it's own file called 'funky.py':</p>
  
  <p>I type the following into my terminal:</p>
  
  <pre><code>python classy.py
  </code></pre>
  
  <p>and it runs fine.</p>
  
  <pre><code>def load_deck():
      suite = ('Spades', 'Hearts')
      rank = ('2', '3')
      full_deck = {}
      i = 0
      for s in suite:
          for r in rank:
              full_deck[i] = "%s of %s" % (r, s)
              i += 1
      return full_deck
  
  print load_deck()
  </code></pre>
  
  <p>When I put the same function in a class, however, I get an error.  </p>
  
  <p>Here's my code for 'classy.py':</p>
  
  <pre><code>class GAME():
      def load_deck():
          suite = ('Spades', 'Hearts')
          rank = ('2', '3')
          full_deck = {}
          i = 0
          for s in suite:
              for r in rank:
                  full_deck[i] = "%s of %s" % (r, s)
                  i += 1
          return full_deck
  MyGame = GAME()
  print MyGame.load_deck()
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "classy.py", line 15, in &lt;module&gt;
  print MyGame.load_deck()
  TypeError: load_deck() takes no arguments (1 given)
  </code></pre>
  
  <p>So, I changed the definition line to the following and it works fine:</p>
  
  <pre><code>def load_deck(self):
  </code></pre>
  
  <p>What is it about putting a function in a class that demands the use of 'self'.  I understand that 'self' is just a convention.  So, why is any argument needed at all?  Do functions behave differently when they are called from within a class?</p>
  
  <p>Also, and this is almost more important, why does my class work without the benefit of using <strong>init</strong> ?  What would using <strong>init</strong> do for my class?</p>
  
  <p>Basically, if someone has the time to explain this to me like i'm a 6 year-old, it would help.  Thanks in advance for any help.</p>