We've explained what strings are in front of us. String can be used
‘‘Or
""Enclosed to indicate.
What if the string itself contains ‘ ? For example, if we want to represent I‘m OK a string, we can say it in " " parentheses:
"I ' m OK"
Similarly, if a string is contained " , we can use it as a ‘ ‘ means of enclosing:
' Learn ' Python "in Imooc '
What if the string contains ‘ and contains both " ?
At this point, you need to "escape" some special characters of the string, and the Python string is \ escaped.
To represent a stringBob said "I‘m OK".
Because ' and ' can cause ambiguity, so we insert a representation before it that \ this is an ordinary character and does not represent the beginning of the string, so the string can be represented as
' Bob said \ ' i\ ' m ok\ '. '
Note: The escape character \ does not count toward the contents of the string.
The usual escape characters are:
\ n indicates a newline \ t means a tab \ \ means \ character itself
Defining strings in Python