Nested Functions
Much like conditionals and iterations, we are allowed to have a function inside a function.
Example: Factors of a Number in a List
There are a lot to unpack here.
We are allowed to define functions within a function
Functions defined within a function can only be called by the parent function (the top most function) this is called a local scope.
This is why we get an error when we try to call isDivisible() outside of the function
The factors() function uses its own isDivisible() function to check if a number is divisible by its own argument
Any variable or argument from the parent function is reference able by its own inner functions
This is why we can reference variable x inside isDivisible()
Last updated