范围是什么意思 [英] What does scope mean

查看:54
本文介绍了范围是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 python 参考手册:

<块引用>

范围 定义块内名称的可见性.如果一个本地变量定义在一个块中,其作用域包括该块.

<块引用>

在代码块中使用名称时,会使用最近的名称进行解析封闭范围.

所以从这个引用中看不出作用域是什么意思.作用域是绑定 name-->value 的集合吗?封闭作用域是什么意思?这是否意味着每个作用域都必须包含对封闭作用域的引用?

解决方案

@Martjin Pieters 的澄清和回答很棒,但我想补充一点,除了 Python,范围是一个计算机科学/编程概念,基本上涵盖所有领域当前使用的编程语言.

要了解更多关于作用域的信息,一般来说,除了在 Python 中之外,我将从这里开始:http://en.wikipedia.org/wiki/Scope_(computer_science)>

包括 Python 在内的许多语言都遵循相同的基本范围规则集,但细节可能因语言而异.因此,如果您真的要问什么是范围?"那么从通用源开始可能比学习 Python 范围界定的复杂性更有用(至少一开始是这样).

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?

解决方案

@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).

这篇关于范围是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆