Primaries represent the most tightly bound operations of the language. Their syntax is:
基元指和语言本身中接合最紧密的若干操作.它们的语法如下:
An attribute reference is a primary followed by a period and a name:
一个属性引用是由一个主元(primary)后跟一个句号和一个名字构成:
The primary must evaluate to an object of a type that supports attribute references, e.g., a module, list, or an instance. This object is then asked to produce the attribute whose name is the identifier. If this attribute is not available, the exception AttributeError is raised. Otherwise, the type and value of the object produced is determined by the object. Multiple evaluations of the same attribute reference may yield different objects.
主元必须是一个支持属性引用的类型的对象.例如, 模块, 列表, 或一个实例. 引用对象属性时, 即要求该被对象生成指定名字的属性. 如果该属性无效, 将会抛出异常AttribError.否则,产生的类型和对象由决定.对同一属性的多次求值是有可能生成不同对象的.
A subscription selects an item of a sequence (string, tuple or list) or mapping (dictionary) object:
一个下标选择一个有序类型对象或映射(字典)对象的一项 :
The primary must evaluate to an object of a sequence or mapping type.
主元(primary)必须是一个有序类型或映射的对象.
If the primary is a mapping, the expression list must evaluate to an object whose value is one of the keys of the mapping, and the subscription selects the value in the mapping that corresponds to that key. (The expression list is a tuple except if it has exactly one item.)
如果主元是一个映射, 则对表达式表求值的结果必须是映射中的一个键, 然后此下标操作在主元映射中选择与该键所对应的值.(如果表达式表只有一项,那么它就是一个元组)
If the primary is a sequence, the expression (list) must
evaluate to a plain integer. If this value is negative, the length
of the sequence is added to it (so that, e.g., x[-1]
selects the last item of x.) The resulting value must
be a nonnegative integer less than the number of items in the
sequence, and the subscription selects the item whose index is that
value (counting from zero).
如果主元是一个有序类型, 表达式表的计算结果应该是一个普通整数.如果这个值是负的, 就加上该主元的长度(所以, 例如, x[-1]选择x的最后一项). 计算结果必须是一个小于主元中所含项数的非负整数, 并且此下标操作选择以该数为索引(从0开始计)的值.
A string's items are characters. A character is not a separate data type but a string of exactly one character.
字符串的元素是字符, 字符不是单独的数据类型而仅仅是只有一个字符长的字符串..