How do nested functions work in Python?

PythonServer Side ProgrammingProgramming

To learn about nested function, refer the following code. In the code, you can see Inner functions can access variables from the enclosing scope, which is the local variable.

def mulFunc(num1):
   def mul(num2):
      return num1 * num2
   return mul
res = mulFunc(15)
// The following prints 300 i.e. 20*15

The above prints the multiplication of num1 and num 2 i.e. 300

Updated on 16-Jun-2020 06:23:45