Yurttas/PL/SL/python/docs/core-python-programming/doc/20/ref/string-conversions.html

Revision as of 20:12, 7 November 2013 by MassBot1 (talk | contribs) (Created page with "<div class="navigation"> {| width="100%" cellspacing="2" align="center" | yurttas/PL/SL/python/docs/core-python-programming/doc/20/ref/dict.html|[[Image:yurttas_PL_SL_p...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


5.2.6 String conversions

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

string_conversion: "`" expression_list "`"

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

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

It is illegal to attempt to convert recursive objects (e.g., lists or dictionaries that contain a reference to themselves, directly or indirectly.)

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.


See About this document... for information on suggesting changes.