Functions can be passed as arguments to other functions:
def apply_twice(f, x):
return f(f(x))
def square(n):
return n * n
result = apply_twice(square, 2)
print(result) # 16 (square of square of 2)
Notice we pass square without parentheses. We're passing the function itself, not calling it.
This pattern is powerful. It lets you write flexible functions that work with any operation.