In Python, a function is an object, just like a number, a string or a list. This simple fact makes powerful techniques possible: passing behaviour as an argument, building tables of operations, and functions that create other functions.
What you can do with a function object
Ability
Example
Assign to another name
say = greet, then say("Nav")
Store in a data structure
ops = [str.upper, str.lower, len]
Pass as an argument
apply(add, [1, 2, 3]), sorted(words, key=len)
Define inside another function
def outer(): def inner(): ...
Return from a function
return inner (a closure)
Assigning creates a second name for the same function; deleting one name with del does not delete the function while another name still refers to it.
Nested functions and closures
A function defined inside another is a nested function. It can read the variables of the enclosing function. If the outer function returns the inner one, the inner function keeps access to those variables even after the outer function has finished; this combination is a closure.
Key takeaways
Functions are objects with names that can be rebound.
They can be stored in data structures and passed as arguments.
Nested functions see the enclosing function’s variables.
Returning an inner function creates a closure that remembers those variables.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain, with an example, why it is useful to pass a function as an argument.
Show worked answer
Passing a function lets one general routine perform different operations without being rewritten. For example, def apply(func, values): return [func(v) for v in values] can square numbers with apply(lambda x: x * x, nums), take absolute values with apply(abs, nums) or round them with apply(round, nums). The loop is written once; the behaviour is chosen by the caller. Built-ins such as sorted(words, key=len) and map() use exactly this idea.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/functions-and-file-handling-in-python/functions-as-objects/ to read this page.