Strings
Strings are used when you need to process text (like names of all kinds, addresses, novels, etc.), not numbers.
You already know a bit about them, e.g., that strings need quotes the way floats need points.
This is a very typical string: "I am a string."
However, there is a a catch. The catch is how to encode a quote inside a string which is already delimited by quotes.
Let's assume that we want to print a very simple message saying:
I like "Monty Python"
How do we do it without generating an error? There are two possible solutions.
The first is based on the concept we already know the escape character, which you should remember is played by the backslash. The backslash can escape quotes too. A quote preceded by a backslash changes its meaning - it's not a delimiter, but just a quote. This will work as intended:
print("I like \"Monty Python\ "")
Note: you don't need to do any escaping here.
Coding strings
Now the next question is: how do you embed an apostrophe into a string placed between apostrophes?
You should already know the answer, or to be precise, two possible answers.
Try to print out a string containing the following message:
I'm Monty Python.
Do you know how to do it? Click Check below to see if you were right:
print('I\'m Monty Python.')
or
print("I'm Monty Python.")
As you can see, the backslash is a very powerful tool - it can escape not only quotes, but also apostrophes.
We've shown it already, but we want to emphasize this phenomenon once more - a string can be empty - it may contain no characters at all.
An empty string still remains a string:
' '
" "