5.2.6 串的转换 String conversions

A string conversion is an expression list enclosed in reverse (a.k.a. backward) quotes:

一个串转换是由一对反引号(`)引用的表达式表.

Download entire grammar as text.

A string conversion evaluates the contained expression list and converts the resulting object into a string according to rules specific to its type.

串的转换先计算所包括的表达式表的值,然后按照其结果类型所特定的规则转换其结果对象为字符串.

If the object is a string, a number, None, or a tuple, list or dictionary containing only objects whose type is one of these, the resulting string is a valid Python expression which can be passed to the built-in function eval() to yield an expression with the same value (or an approximation, if floating point numbers are involved).

如果结果对象属于字符串, 数值, None, 或元组,字典其中的一个类型, 那么结果串就是可以通过传递给内建函数eval()来生成一个具有与原值相同的正确的Python表达式(或, 对于浮点数来说生成的是近似数).

(In particular, converting a string adds quotes around it and converts ``funny'' characters to escape sequences that are safe to print.)

(特别地, 经增加反引号转换的字符串和由特殊字符串所转换得到的转义字符串是能够显示输出的.)

Recursive objects (for example, lists or dictionaries that contain a reference to themselves, directly or indirectly) use "..." to indicate a recursive reference, and the result cannot be passed to eval() to get an equal value (SyntaxError will be raised instead).

试图转换一个递归对象是无效的(例如, 一个直接或间接地包含有对自身引用的列表或字典.)

The built-in function repr() performs exactly the same conversion in its argument as enclosing it in parentheses and reverse quotes does. The built-in function str() performs a similar but more user-friendly conversion.

内建函数repr()作相同的转换: 将其括号中的参数转换成用反引号引用它后的结果. 内建函数str()与之类似,但结果更具可读性.