3 ms·
How are they different? Both produce the same end result, Python manages this syntax just fine.
by Igglyboo 12y ago
How are they different? Both produce the same end result, Python manages this syntax just fine.
- exogen 12y ago"Just fine" is papering over the fact that people get tripped up by this in Python all the time – sometimes you need to use the `global` or `nonlocal` statements to resolve the ambiguity. https://docs.python.org/3/reference/simple_stmts.html#global https://docs.python.org/3/reference/simple_stmts.html#global https://docs.python.org/3/reference/simple_stmts.html#nonlocal https://docs.python.org/3/reference/simple_stmts.html#nonloc... Classic example: http://stackoverflow.com/questions/9264763/unboundlocalerror-in-python http://stackoverflow.com/questions/9264763/unboundlocalerror... If you search for UnboundLocalError on StackOverflow, there are 918 results. Not all of them are due to this particular scoping ambiguity, but many of them are.
- lmm 12y agoIt's a mistake even in Python. It makes typos harder to catch. And a visible distinction between variables that change and values that don't makes code much easier to reason about.