is it possible to store a variable from a while loop to a function and then call that same variable from the function at the end of the loop
for eg:during while loop, p
No, you can't do this.
Also, it's a terrible, terrible idea. "Store to a function" is such an awful and wrong thing to do that I hesitate to provide working code.
Use a callable object.
class Store( object ):
def __init__( self ):
self.x, self.y, self.z = None, None, None
def __call__( self, x=None, y=None, z=None ):
if x is None and y is None and z is None:
return self.x, self.y, self.z
else:
self.x, self.y, self.z = x, y, z
What's better is to do something simpler that doesn't involve a function with magical properties that does two different things when called with and without arguments.
Anything is better than "store to a function". Anything.
Really.
Anything.