In which order many functions are executed in a python code
Erik
python at lucidity.plus.com
Fri Jun 9 18:00:37 EDT 2017
On 09/06/17 19:39, sondes kalboussi wrote:
> Am a bit confused I was thinking that the order of execution of
> functions in a code is from the first to the last function but
> sometimes it is the opposite, for instance, some parameters or
> outputs from the second function are called in the first one even
> thou they are not global, any hints ?
As a complete and utter guess, I assume you are talking about something
like:
result = func1(1, 2, func2(x, y))
In this case, func2() will be called before func1(). This is because
func1() needs three parameters and one of those parameters is the return
value of func2().
Python can not know the return value of func2() without calling it.
Therefore, to be able to call func1() and give it its three parameters,
it must first call func2() to find out what that third parameter value is.
It's equivalent to:
func2result = func2(x, y)
result = func1(1, 2, func2result)
If that is _not_ what you are talking about, then like Thomas says - you
need to paste some code and explain what you are confused by.
E.
More information about the Python-list
mailing list