title: Python - Function Return Value
body: <p>This example is just a basic program - I'm a new Coder - learning and experimenting whilst messing about .. Currently testing on Python 3.6 IDE and PyCharm - apologies for double spacing code - but looks a mess without.</p>
  
  <p>Looking for guidance for returning a value from a function.</p>
  
  <p>Have tried dozens of different methods / searched the forum, but closest answer this layman could understand stated I needed to use the return value otherwise it will be forgotten .. So added <em>print(age_verification, " example test value .. ")</em> at various locations - but nothing gets returned outside the function ..</p>
  
  <p>Have tried returning Boolean / integer / string values and adapting - nothing with each variant .. Added a default <em>age_verification = False</em> variable before the function // or // referenced within function for 1st time .. Doesn't effect the return value except IDE doesn't state "unresolved reference"</p>
  
  <p>Tried a line-by-line python visualizer - but again - age_verification value disappears instantly after exiting the function . :-(</p>
  
  <p>==================================================================</p>
  
  <p><strong>Using 1 Single Function</strong></p>
  
  <pre><code>def age_veri(age, age_verification) :
  
    if age &lt; 18 :
  
      age_verification = False
  
      print(age_verification, " is false .. Printed to test variable ..")
  
      return age_verification
  
    elif age &gt;= 18:
  
      age_verification = True
  
      print(age_verification, " is True.. Printed to test variable ..")
  
      return age_verification
  
    return age_verification # ( -- have tested with/without this single-indent line &amp; with/without previous double-indent return age_verification line.)
  
  age=int(input("Enter Your Age : ")
  
  age_verification = False # ( -- have tried with / without this default value)
  
  age_veri(age, False)
  
  if age_verification is False:
  
    print("You failed Verification - Age is Below 18 .. ")
  
  elif age_verification is True:
  
    print("Enter Website - Over 18yrs")
  
  else:
  
    print(" Account not Verified .. ")
  </code></pre>
  
  <p>==================================================================</p>
  
  <p><strong>Same Example - Using 2 Functions</strong></p>
  
  <pre><code>def age_variable(age):
  
     if age &lt; 18:
  
        age_verification = False
  
        print (age_verification, " printing here to use value and help test function..")
  
        return age_verification
  
     elif age &gt;= 18:
  
        age_verification = True
  
        print (age verification, " printing here to use value and help test function..")
  
        return age_verification
  
     return age_verification (tried with and without this line - single indent - same level as if / elif) 
  
  def are_verified(age_verification):
  
     if age_verification is False:
  
        print("Age Verification Failed .. ")
  
     elif age_verification is True:
  
        print("Visit Website .. ")
  
     else:
  
        print("Verification Incomplete .. ")
  
  age = int(input("Enter Your Age : ")
  
  age_variable(age)
  
  are_verified(age_verification)
  </code></pre>
  
  <p>==============================================================</p>
  
  <p>Any advice is appreciated - wasted most of today hitting my head against the wall .. And apologies in advance .. Know it'll be something really basic - but appear to be using same formatting as others :-)</p>
  
  <p><strong>THANK YOU</strong></p>