python store variable in function and use it later

前端 未结 5 1507
星月不相逢
星月不相逢 2021-02-06 18:01

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

5条回答
  •  面向向阳花
    2021-02-06 18:38

    Technically speaking, if you had a deep, burning desire to do this with functions, you can always do it with a closure (which is, as we all know, a poor man's object):

    def store(a,b,c):
        def closure():
            return (a,b,c)
        return closure
    
    stored = store(1,2,3)
    print stored()
    

    prints in (1,2,3)

提交回复
热议问题