2.3 标识符和关键字 Identifiers and keywords
Identifiers (also referred to as names) are described by the following lexical definitions:
标识符(也叫做名字)由以下词法定义描述:
-
Download entire grammar as text.
identifier::= (letter|"_") (letter | digit | "_")*letter::= lowercase | uppercaselowercase::= "a"..."z"uppercase::= "A"..."Z"digit::= "0"..."9"
Identifiers are unlimited in length. Case is significant.
标识符不限长, 区分大小写.
2.3.1 关键字 Keywords
The following identifiers are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers. They must be spelled exactly as written here:
以下标识符用作保留字, 或者叫做语言的关键字, 并且不能作为普通标识符使用, 而且它们必须像下面的那样严格拼写.
and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print
Note that although the identifier as can be used as
part of the syntax of import statements,
it is not currently a reserved word.
In some future version of Python, the identifiers
as and None will both become
keywords.
2.3.2 保留的标识符类型 Reserved classes of identifiers
Certain classes of identifiers (besides keywords) have special meanings. These classes are identified by the patterns of leading and trailing underscore characters:
(关键字以外的)某些类型的标识符具有特殊的含义, 如下:
_*- Not imported by "from module import
*". The special identifier "_" is used
in the interactive interpreter to store the result of the last
evaluation; it is stored in the __builtin__
module. When not in interactive mode, "_" has
no special meaning and is not defined. See section 6.12,
``The import statement.''
不能通过" from moduls import *"导入。 特定标识符"_"在交互式解释器用于存储上次估值的结果. 它位于__buildin__模块之中. 在非交互方式时,"_"没有特殊含义, 且是未定义的
Note: The name "_" is often used in conjunction with internationalization; refer to the documentation for the gettext module for more information on this convention.
__*__- System-defined names. These names are defined by the
interpreter and it's implementation (including the standard
library); applications should not expect to define additional names
using this convention. The set of names of this class defined by
Python may be extended in future versions. See
section 3.3,
``Special method names.''
系统定义的名字
__*- Class-private names. Names in this category, when used within
the context of a class definition, are re-written to use a mangled
for to help avoid name clashes between ``private'' attributes of
base and derived classes. See section 5.2.1,
``Identifiers (Names).''
类私有名字