Python original string, python string
1 str1 = 'let's go '2 File "<input>", line 13 str1 = 'let's go '4 ^ 5 SyntaxError: invalid syntax
Because str1 contains "'", the compiler cannot escape and report an error. The correct code is as follows:
Str1 = 'let \'s go 'str1 "let's go"
Use \ as the escape character to escape the characters in the string
1 str2 = 'C: \ now '2 str23' C: \ now '4 print (str2) 5 C: 6 ow
The \ n in str2 is the Escape Character of the line break, so the output format is new. You can use the original string Escape Character r.
Str2 = r 'C: \ now 'print (str2) C: \ now
However, the backslash cannot be at the end of the string.
Str2 = r'c: now \ 'file "<input>", line 1 str2 = r'c: now \ '^
In this way, the compiler considers \ as an escape character escape, which can be written in this way.
1 str2 = r 'C: \ now '+' \ '2 print (str2) 3 C: \ now \