|
|
|
|
|
by fny
1373 days ago
|
|
`f` behaves just like closure. It can even be assigned to a variable. def f(x): x = 2 # <- this `x` is the same `x` as in the argument, it can be access via locals() internally
You can even assign `f`. For example, `function = f`.Python is call by reference. Change my mind. `def f(x): x[0] = 1` will manipulate whatever object you pass to it. |
|
Additionally, for something to be a closure it has to close over something (an environment). What does `f` or `g` close over? Note that they aren't changing any environment, they are "merely" functions, not closures. Python does have closures, but those aren't examples of them.
And being able to assign a function to a variable does not make a closure, or do you think that C has closures because it has function pointers?