On Sun, 12 Apr 2015 01:00 am, jonas.thornv...@gmail.com wrote:

> If two functions crossreference eachother back and forth what happen with
> the local variables.

Nothing. They are local to the function that creates them.


> Will there be a new instance of function holding the variables or do they
> get messed up?

No to both of those. You have two functions, each with it's own locals.


def spam():
    colour = "red"
    print("Inside spam: colour is:", colour)
    eggs()
    print("Inside spam after calling eggs: colour is:", colour)
    eggs()


def eggs():
    colour = "yellow"
    print("Inside eggs: colour is:", colour)


Calling spam() gives you this output:

py> spam()
Inside spam: colour is: red
Inside eggs: colour is: yellow
Inside spam after calling eggs: colour is: red
Inside eggs: colour is: yellow


Even if the functions call each other (mutual recursion) each function's
local variables remain local.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to