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