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:
def func():
a = 100;
return a;
val = func();
print val;
Is val having a dangling pointer? Or garbage collector will never delete a memory location if there is a variable pointing to it even if memory is created in stack (inside a function)? In our example variable "a".