title: Is returning local variable from function safe in python?
body: <p>As per my understanding when we return a local variable from a function in python, a reference to that memory location is returned.
  Also, local variable will/can be deleted by garbage collector once function execution is over.
  So my question is "Is it safe to return local variable from function in python?"
  Example:</p>
  
  <pre><code>def func():
      a = 100;
      return a;
  
  val = func();
  print val;
  </code></pre>
  
  <p>Is val having a dangling pointer? Or garbage collector will never delete a memory location if there is a variable pointing to it <strong>even if memory is created in stack (inside a function)? In our example variable "a".</strong> </p>