# Assigning a function to a variable
def greet(n):
return f"Hello, {n}!"
say_hi = greet # Assign the greet function to say_hi
print(say_hi("Alice")) # Output: Hello, Alice!
# Passing a function as an argument
def apply(f, v):
return f(v)
res = apply(say_hi, "Bob")
print(res) # Output: Hello, Bob!
# Returning a function from another function
def make_mult(f):
def mult(x):
return x * f
return mult
dbl = make_mult(2)
print(dbl(5)) # Output: 10