3 ms·
If Python were fully call by reference then: def g(y): y = 3 x = 10 g(x) x # => ?? If it's 3 then it's pass by reference here, if it's 10 it's pas
by Jtsummers 4y ago
If Python were fully call by reference then:
def g(y):
y = 3
x = 10
g(x)
x # => ??
If it's 3 then it's pass by reference here, if it's 10 it's pass by reference. Which is 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?
- Jtsummers 4y agoOops: If it's 3 then it's pass by reference here, if it's 10 it's pass by value. Which is it? (Don't hit reply when you're rushing out the door.)