

In other words, we have used the double quote and backslash in combination ( \"). What happening actually? The escape character gives a new behavior to the character, i.e., a double quote (") next to it. # double-quotes inside a doubled quotesĪs you see, we didn't get any errors. Put a backslash before the quote that you wish to have in your text.
#ANSI ESCAPE SEQUENCES PYTHON HOW TO#
As we are talking about the escape character, let's see how to use it to get rid off the error.

How to resolve our problem? We can do it in several ways. Consequently, run the same example and see the output. But, in our example, we have a double pair of the same kinds of quotes. In other words, the interpreter accepts only one pair of quotes of a similar type. We have used double quotes to close the text and, at the same time, used double quotes inside the outer pair of double-quotes.Ĭonsequently, it confuses the interpreter. We have tried to print " ToolsQA" earlier using print( ""ToolsQA"") statement, and it didn't work !! Why did we get an error? It's because of the quotes that we have used in the text. Let's see the most common examples of escape sequences. Moreover, in Python, we have different escape sequences that have a unique meaning. The sequence of characters after a backslash is known as an escape sequence. Let's see what escape sequences are and how to use them in Escape Sequences in Python. It could be printing double quotes or indicating a new line. That is to say backlash signifies that the next character after it has a different meaning. As the name suggests, the escape character escapes the characters in a string for a brief moment to introduce unique inclusion. The programmers refer to the " backslash (\)" character as an escape character. In other words, it has a special meaning when we use it inside the strings. Here is what we will cover in this tutorial This is where escape sequences in Python come for our rescue.Īdditionally, we will also get to know some other fantastic stuff. So what if we need to print something which already has a double quote? Can we use multiple double quotes in this case? Something like print ( " "ToolsQA" ")? No, it doesn't work, unfortunately. With this knowledge, let's try to print " ToolsQA" - Sounds simple? We know we can print anything using a print function with a double-quote inside. We know an excellent deal about print function now.
