use of backslah | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

use of backslah

The preparation kit just had this question Complete the code to create a string containing a double quote. >>> "--" ans: \" why wouldn't the answer be just ( " ) and why it needs a back slash

30th Mar 2020, 2:08 PM
Mani
Mani - avatar
1 Answer
+ 3
(") is a double quote within parentheses. It's not a string, let alone a string containing a double quote. In fact, it doesn't quite mean anything in Python, hence it can't possibly be the answer. Certain characters are illegal in a string. A string containing a double quote would look like """ if unescaped. To the interpreter, this looks like a triple quote. Instead, you escape the double quote using a backslash. "\"" so that the interpreter understands that the double quote is part of the string instead of a closing quote. https://www.w3schools.com/python/gloss_python_escape_characters.asp
30th Mar 2020, 2:30 PM
Hatsy Rei
Hatsy Rei - avatar