![]() |
VOOZH | about |
Functions are first-class objects, which means they can be assigned to variables just like any other value. Once a function is assigned to a variable, the function can be called using either the original function name or the variable.
GFG
Explanation:
Note: When assigning a function to a variable, use the function name without parentheses. Writing func = show assigns the function itself, while func = show() executes the function and assigns its return value.
def function_name(parameters):
# function body
passvariable_name = function_name
variable_name(arguments)
Where:
Example 1: The following example demonstrates assigning a function to a variable and calling it using that variable. It also shows the difference between local and global variables.
123 98 123 98 123
Explanation:
Example 2: The following example assigns a function that accepts a parameter to a variable and calls it using that variable.
Odd number Even number Odd number
Explanation:
Example 3: The following example assigns a function that returns a value to a variable and calls it using that variable.
240 400 4000
Explanation: