Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88822
| References | <dcb7fd6b-3a96-47e8-91f6-49b21f7bf605@googlegroups.com> |
|---|---|
| Date | 2015-04-12 01:15 +1000 |
| Subject | Re: Generarl programming question. |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.222.1428765309.12925.python-list@python.org> (permalink) |
On Sun, Apr 12, 2015 at 1:00 AM, <jonas.thornvall@gmail.com> wrote:
> If two functions crossreference eachother back and forth what happen with the local variables.
>
> Will there be a new instance of function holding the variables or do they get messed up?
You mean if one function calls another, and that function calls the
first? That's called "mutual recursion":
def func1(x):
if x % 2: return x + 1
return func2(x - 2)
def func2(x):
if x % 3: return x + 2
return func1(x - 3)
The 'x' inside each function is completely separate, no matter how
many times they get called. They're usually stored on something called
a "call stack" - you put another sheet of paper on top of the stack
every time you call a function, local variables are all written on
that paper, and when you return from a function, you discard the top
sheet and see what's underneath.
For more information, search the web for the key terms in the above
description, particularly the ones I put in quotes.
If this isn't what you're talking about, the best way to clarify your
question is probably to post a simple (even stupidly trivial, like the
one above) example, and ask a question about that code. Someone'll
doubtless help out!
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Generarl programming question. jonas.thornvall@gmail.com - 2015-04-11 08:00 -0700
Re: Generarl programming question. Chris Angelico <rosuav@gmail.com> - 2015-04-12 01:15 +1000
Re: Generarl programming question. jonas.thornvall@gmail.com - 2015-04-11 08:22 -0700
Re: Generarl programming question. Chris Angelico <rosuav@gmail.com> - 2015-04-12 01:28 +1000
Re: Generarl programming question. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-11 18:23 +0200
Re: Generarl programming question. Terry Reedy <tjreedy@udel.edu> - 2015-04-11 14:47 -0400
Re: Generarl programming question. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-11 21:19 +0200
Re: Generarl programming question. Terry Reedy <tjreedy@udel.edu> - 2015-04-11 17:12 -0400
Re: Generarl programming question. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-12 00:05 +0200
Re: Generarl programming question. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 15:04 +1000
Re: Generarl programming question. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 01:25 +1000
Re: Generarl programming question. jonas.thornvall@gmail.com - 2015-04-11 08:36 -0700
csiph-web