So, in this example,

the first argument is square.

So, Python is going to compute the value of

this expression and then it's going to compute the value of

this expression and then finally after Python knows

what function it's calling and what the value of every argument is,

then Python is going to finally call

the function and then

the value that that function call returns

is going to be the value of this overall expression.

So, let's see that in action.

So, here we assign X to five and Y to seven and the first thing that Python does,

is it evaluates this add function.

So, it sees that adds a function and so the next thing that it does,

is it evaluates each one of its arguments.

So, first, it evaluates this sub-expression and it sees that square itself

is a function and so it's going to repeat

that process and it looks up square and finds that it's a function.

Then it repeats that process, looks up Y,

finds that its value is seven and then it's going to call square on seven and get 49.

Then it's going to look up the value of

this square function and it's going to see that it's

a function it's going to compute the value of each one of its arguments.

So, it's going to see that X is five and then it's going to

call square on five to get 25.

So, far what Python did,

was it found what's the value of ad and then it computed the value of

its two arguments and then it ended up getting 49 as

the first argument and 25 as

the second argument and so now that we have the function itself,

and all of the arguments then we can finally call the function

add on 49 and 25 and as a result,

we're going to get 74 as the value of this overall expression.

Now, suppose that we have this complex expression square of X plus sub square of

Y and two times X and we're asked to

figure out what order is Python actually going to evaluate these arguments in.

Now, bear with me for a bit as I drag each one of these blocks in the correct order.

Okay. So, the first thing that Python is going to do,

is it's going to try to look up the square function and so if we see yep

lookup the variable square to get the function object and then it

needs to compute the value of each one of its arguments.

So, here there's only one argument and so the first thing that Python is

going to do when figuring out what's the value of X plus sub of this function,

is it's first going to look up the value of X because that's leftmost.

So, it's going to be look up the value of variable X.

So, I'm going to get lookup the value of variable X to get two.

Then before we can add X plus this expression,

then we need to compute the value of this expression.

So, when computing the value of this expression,

then we need to in turn lookup the value of the sub-function.

So, we need to look up the variable sub to get

that function object and then we're computing the value of its arguments.

So, the first argument is square of Y.

So, in order to get this,

we need to look up what's the square function.

So, we look up the variable square again to get

the function object and then we need

to compute the value of its argument so we need to look up the value of Y.

So, we'd look up the value of Y to get three and then we back

up and we need to compute the value

of the second argument to sub and in order to do that,

we need to look up X again to get two and we need to multiply two-by-two to get four.