|
|
|
|
|
by phren0logy
5350 days ago
|
|
At the risk of exposing my ignorance, I thought >Other “common wisdom”, like using locals instead of globals, yields relatively little gain. this advice was typically more related to avoiding collisions with variable names, rather than performance? |
|
Python has full dynamic scoping, which means that inside a function you can refer to any variables set in outer scopes. Because Python is a dynamic language, every time you refer to a variable, the Python interpreter looks for it in the local scope first, and then each enclosing scope until it hits the containing module. A local variable will always be found in the first iteration of that loop, a global variable will take at least two iterations.