title: Passing class variables into class methods
body: <p>How do I pass class variables into class methods? I wrote a program to  recursively swap every second character of a string. </p>
  
  <p>Since I could not pass self.inputstring as arguments I decided to use a nested function.</p>
  
  <p>Is there a better solution? Is it possible to use class variables as arguments?</p>
  
  <pre><code>class Swap(object):
  
  def __init__(self, astring):
  
      self.acc = ""
      self.count = 1
  
      self.inputstring = astring
      self.checkstring = astring
  
  def swap2(self):
  
      string = self.inputstring
  
      def swaphelper(string):
  
          if len(string) == 2:
              self.acc = self.acc + string[1] + string[0]
              self.count = self.count + 2
          if len(self.checkstring) == len(self.acc):
              return self.acc
  
          if len(self.checkstring) != len(self.acc):
              return swaphelper(self.inputstring[self.count-1:self.count+1])
  
      return swaphelper(string)
  
  
  c = Swap("I'm a string")
  
  d = c.swap2()
  </code></pre>