What does scope mean [duplicate]

谁说我不能喝 提交于 2020-01-06 19:57:41

问题


From python reference manual:

A scope defines the visibility of a name within a block. If a local variable is defined in a block, its scope includes that block.

and

When a name is used in a code block, it is resolved using the nearest enclosing scope.

So it is not obviously from this quotes what scope does mean. Is it true that scope is a collection of bindings name-->value? And what does mean enclosing scope? Does it mean that every scope must contain a reference to the enclosing scope?


回答1:


@Martjin Pieters clarifications and answers are awesome, but I'd like to add that beyond python, scope is a computer science/programming concept that spans across basically all programming languages currently in use.

To learn more about what scope is, generally, aside from in python, I'd start here: http://en.wikipedia.org/wiki/Scope_(computer_science)

Many languages, including python, follow the same set of basic scoping rules, but the details can be different between languages. Thus, if you're really asking "what is scope?" then starting at a general source may be more useful than learning the intricacies of python's scoping (at least at first).



来源:https://stackoverflow.com/questions/22042619/what-does-scope-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!