• Earlier we explained what a string is. Strings can be enclosed in brackets of “” or “”.
  • What if the string itself contains’? For example, if we want to represent the string I’m OK, we can use “” to represent it:

    "I'm OK"
  • Similarly, if the string contains “, we can use “to represent:

    'Learn "Python" in imooc'
  • What if the string contains both ‘and’?

    At this point, some special characters of the string need to be “escaped”, and Python strings are escaped with \.

    To represent a string

    Bob said "I'm OK".
  • Since ‘and “are ambiguous, we insert a \ before it to indicate that this is an ordinary character and does not represent the beginning of the string, so that the string can again be represented as

    'Bob said \"I\'m OK\".'
  • Note: The escape character \ is not counted in the content of the string. Other commonly used escape characters are: \n for newline \t for a TAB character \ for the \ character itself