def maker(n): def action(x): return x ** n return action f = maker(2) print(f) print(f(3)) print(f(4)) g = maker(3) print(g(3)) print(f(3)) # stil
Because at the time when you create the function, n was 2, so your function is:
n
2
def action(x): return x ** 2
When you call f(3), x is set to 3, so your function will return 3 ** 2
x
3
3 ** 2