3 ms·
It should be saved as its value at the point of greet's definition, but Python appears to not have real closures, so the change in the value of string afterward
by dazmax 17y ago
It should be saved as its value at the point of greet's definition, but Python appears to not have real closures, so the change in the value of string afterwards changes it in greet too.
- oconnor0 17y agoWhy do you say that the value should be saved at its definition? I realize Java does that (with anonymous classes & final), but allowing mutation of closured state lets you fairly easily write things - like an OO class system, if you want to.
- algorias 17y agoWhat does "real" mean? When you use closures (or not-quite-closures, or however you want to call them) in python, they work just like "real" closures, except for the pathological case of defining functions in loops.