Re:Understanding a Python Closure Oddity
by b3orn on Monday June 17, 2024 @11:20AM
(#40706498)
It's unrelated to the for loop, the for only changes the variable, there are other ways you can do that and you'll run into the same "oddity"
[ Parent
| on HN ]
I get why it behaves like this, but I find it odd that Python claims to have "lexical scoping". This is not lexical (as you read it). This is based on somewhat hidden reference lookups.
Re:Understanding a Python Closure Oddity
by abecedarius on Monday June 17, 2024 @08:40PM
(#40712870)
> for changes the variable
That's a design decision, not a law of nature. JS 'for let' lacks this problem; probably the committee would have named it just 'for' if not for legacy.