We already learnt a little bit about strings in Python3 Basics: Strings and Functions, but in this tutorial we are going to go a little deeper and also see some helpful functions Python provides for strings.
String literals can be enclosed by either single or double quotes, although single quotes are more commonly used. For example, 'Hello World' or "Hello World".
To type in some special characters, you have to type in a backslash escape. For example, \' is a single quote, \" is a double quote, \\ is a backslash, \t is a tab and \n is a newline. For example:
type=codeblock|id=py3_string_escaping|autocreate=python3print('Alice said \'How do you do?\'.\nBob replied, \'Very well thank you!\'')
type=codeblock|number=0|highlight=0Alice said 'How do you do?'.Bob replied, 'Very well thank you!'
A double quoted string literal can contain single quotes without any fuss (e.g. "I didn't do it") and likewise single quoted string can contain double quotes.