title: Python: passing values from function to function
body: <p>I've been fighting with this for three hours now. </p>
  
  <p><strong>ETA- Should have mentioned this, but for purposes of this class, not allowed to use global variables.</strong></p>
  
  <p>Within function main(), I want to run a function firstPass if and only if it's the first time the whole function is being run. The firstPass function initializes a couple variables and prints some information that is not interesting if it's not the first time you see it. </p>
  
  <p>I duly have:</p>
  
  <pre><code>#Initialize variables that need to run before we can do any work here
  count = 0
  
  def firstPass():
      x = 5
      y = 2
      print "Some stuff"
      count = count + 1
      print "Count in firstPass is",count
      return count,x,y
  
  def main ():
      print "Count in main is",count
      if count == 0:
          firstPass()
      else:
          #Do a whole bunch of other stuff that is NOT supposed to happen on run #1
          #because the other stuff uses user-modified x and y values, and resetting
          #to start value would just be self-defeating.
  
  main()
  </code></pre>
  
  <p>This returns correctly on the first pass, but on subsequent passes, returns:</p>
  
  <pre><code>Count in main is 1
  </code></pre>
  
  <p>This is also a problem for my user-modified x and y values within other functions. Though I haven't modified them here, I did include them because I need to pass multiple values between functions later on in the code, but who wants to read all that when I could just put them here for the sake of the example...</p>
  
  <p>I was under the impression that </p>
  
  <pre><code>return [variable]
  </code></pre>
  
  <p>passed the CURRENT (i.e. whatever that variable became within the current function) value of the variable back to other subsequent functions. Either my understanding is wrong, or I am just doing it wrong.</p>