What other escape sequences are there?

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.

10 Likes

Hi! I’ve been using Code Academy for a short time. I’ve seen a few people refer to some type of “documentation”. Where can it be found? Thanks! :smile:

2 Likes

Here: https://docs.python.org/3/index.html

8 Likes

2 posts were merged into an existing topic: What does the backslash in the variable declaration mean? (=\)