Strings in Python
Strings in Python
String Literal
If a string begins with a single quote, it must end with a single quote. The same
applies to double-quoted strings. You can not mix the type of quotes.
Escape Sequences
To include a quote within a string, use an escape character (\) before it. Otherwise
Python interprets that quote as the end of a string and an error occurs. For example,
the following code results in an error because Python does not expect anything to
come after the second quote:
>>> storm_greeting = 'wow, you're dripping wet.'
SyntaxError: invalid syntax
The escape sequence \' indicates that the second quote is simply a quote, not the
end of the string:
>>> storm_greeting = 'Wow, you\'re dripping wet.'
"Wow, you're dripping wet."
String Operators
The * and + operands obey by the standard precedence rules when used with
strings.