What other escape sequences are there?


#1

Question

In the context of this exercise, what other escape sequences are there?

Answer

There are several other escape sequences available in addition to \n and \t. A few useful ones to know about are the following.

The quotation escape sequences \' and \" are useful when adding these quotes within a string wrapped in the same type of quotations.

# Single quotations
string = 'I\'m coding!'
print(string) # I'm coding!

# Double quotations
string2 = "\"Hello World!\""
print(string2) # "Hello World!"

Another useful escape sequence to know about is the backslash \\, which allows you to show backslashes without it converting to some escape sequence in the string.

string3 = "The \\n escape sequence adds a newline"
print(string3) # The \n escape sequence adds a newline

For the rest of the available escape sequences, feel free to check out the documentation.