Using a single backslash as a continuation character is an alternative to using triple quoted strings when you are construction a string constant. Thus, the following two expressions are equivalent, but most programmers prefer the convenience of not having to use backslashes which is offered by triple quotes.
threelines = 'First\ Second\ Third' threelines = '''First Second Third'''
The backslashed quote symbols are useful if you need to create a string with both single and double quotes. (If you have only one kind of quotes in your string, you can simply use the other kind to surround your string, since the two types of quotes are equivalent in python.)
As Table 2.1 shows, you can produce a backslash in a string by typing two backslashes; note that only one of the backslashes will actually appear in the string when it's printed. There are certain situations (most notably when constructing regular expressions (Section 8.5)), when typing two backslashes to get a single backslash becomes tedious. Python provides what are called raw strings, in which the character sequences shown in Table 2.1 have no special meaning. To construct a raw string, precede the opening quote character with either a lowercase or uppercase ``R'' (r or R). Note, however that a backslash cannot be the very last character of a raw string. Thus, these two expressions are equivalent:
>>> print 'Here is a backslash: \\ ' Here is a backslash: \ >>> print r'Here is a backslash: \ ' Here is a backslash: \