5.3.2 下标 Subscriptions

A subscription selects an item of a sequence (string, tuple or list) or mapping (dictionary) object:

一个下标选择一个有序类型对象或映射(字典)对象的一项 :

Download entire grammar as text.

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.

字符串的元素是字符, 字符不是单独的数据类型而仅仅是只有一个字符长的字符串..