Strings

Besides numbers, Python can also manipulate strings, which can be expressed in several ways. They can be enclosed in single quotes ('...') or double quotes ("...") with the same result.

In the interactive interpreter, the output string is enclosed in quotes and special characters are escaped with backslashes. While this might sometimes look different from the input (the enclosing quotes could change), the two strings are equivalent. The string is enclosed in double quotes if the string contains a single quote and no double quotes, otherwise it is enclosed in single quotes.

See also

Sequence Types — str, unicode, list, tuple, bytearray, buffer, xrange
Strings, and the Unicode strings described in the next section, are examples of sequence types, and support the common operations supported by such types.
String Methods
Both strings and Unicode strings support a large number of methods for basic transformations and searching.
String Formatting
Information about string formatting with str.format() is described here.
String Formatting Operations
The old formatting operations invoked when strings and Unicode strings are the left operand of the % operator are described in more detail here.

 

This entry was posted in Uncategorized. Bookmark the permalink.