must escape the surrounding quote character to embed it in the string that isr\is not valid string literal-- raw string cannot end in an odd number of backslashes if you need to end raw string with single backslashyou can use two and slice off the second ( ' \nb\tc\'[:- ])tack one on manually ( ' \nb\tc'\\')or skip the raw string syntax and just double up the backslashes in normal string (' \nb\\tc\\'all three of these forms create the same eight-character string containing three backslashes triple quotes code multiline block strings so faryou've seen single quotesdouble quotesescapesand raw strings in action python also has triple-quoted string literal formatsometimes called block stringthat is syntactic convenience for coding multiline text data this form begins with three quotes (of either the single or double variety)is followed by any number of lines of textand is closed with the same triple-quote sequence that opened it single and double quotes embedded in the string' text may bebut do not have to beescaped-the string does not end until python sees three unescaped quotes of the same kind used to start the literal for example (the here is python' prompt for continuation lines outside idledon' type it yourself)mantra """always look on the bright side of life ""mantra 'always look\ on the bright\nside of life this string spans three lines as we learned in in some interfacesthe interactive prompt changes to on continuation lines like thisbut idle simply drops down one linethis book shows listings in both formsso extrapolate as needed either waypython collects all the triple-quoted text into single multiline stringwith embedded newline characters (\nat the places where your code has line breaks notice thatas in the literalthe second line in the result has leading spacesbut the third does not--what you type is truly what you get to see the string with the newlines interpretedprint it instead of echoingprint(mantraalways look on the bright side of life in facttriple-quoted strings will retain all the enclosed textincluding any to the right of your code that you might intend as comments so don' do this--put your comments above or below the quoted textor use the automatic concatenation of adjacent strings mentioned earlierwith explicit newlines if desiredand surrounding parentheses to string fundamentals