In the example, how does fun_one know what m is?


#1

Question

In the example, how does fun_one know what m is?

Answer

In the example, how does fun_one know what m is?
i. Since we’re using fun_one() inside of fun_two(), and fun_two() accepts m as a parameter, we
provide that value, whatever it may be, to fun_one() to use as its own parameter – n. Step by step,
what happens is:
1. We use fun_two() and provide some argument for m, like this: fun_two(10).
2. Inside, it makes a call to fun_one() and passes m (which we provided as 10) because it accepts
one argument.
3. fun_one() takes 10 as its n value and multiplies it by 5 and returns the resulting value – 50.
4. Back in fun_two() we now have 50 + 2, so the function returns 52, and that’s it!
Any time you’re unsure of how nested functions are working, it can be helpful to go through step by step like this, even writing it out on paper.


FAQ: Learn Python: Functions - Calling Functions
#2

What is a little confusing to me is that a parameter can be changed from (n) to (m) and that fun_one would accept that even though its orginal paramter was (n). I would assume just from looking at this, that it would return an error saying that there was no argument assigned to (n) in the first place.