+ 1

I am still confused with (\", \') backslash escape characters in python. What is the use of these characters in python?

I also searched many queries related to this topic but still failed to understand.

7th Jul 2020, 5:13 PM
Sarfira
Sarfira - avatar
8 Answers
+ 4
So, you need to tell python that you don't want to close the string at 'don', you need to escape it, by putting a backslash. Then python knows that it doesn't have to close the string there: 'Don\'t'
7th Jul 2020, 5:40 PM
Arnesh
Arnesh - avatar
+ 4
But how would python know what you want? 'don' looks like a string too.
7th Jul 2020, 5:35 PM
Arnesh
Arnesh - avatar
+ 4
Welcome :)
7th Jul 2020, 5:41 PM
Arnesh
Arnesh - avatar
+ 3
print("He said, 'These are quotation marks in python("") '. ") In this, the string becomes: He said, 'These are quotation marks in python( Because the quotation ends the line. In these cases, escape characters are used: print("He said, 'These are quotation marks in python(\"\") '. ") Output: He said, 'These are quotation marks in python("") '.
7th Jul 2020, 5:21 PM
Arnesh
Arnesh - avatar
+ 3
a = 'Don't!' In this, what do you expect the value of a? Don't or Don ? If you forget the part t!', doesn't 'don' seem like a complete string?
7th Jul 2020, 5:32 PM
Arnesh
Arnesh - avatar
+ 1
Thanks ! But sorry your output makes me more confused can you elaborate in easy way if you don't mind?
7th Jul 2020, 5:27 PM
Sarfira
Sarfira - avatar
+ 1
Don't!
7th Jul 2020, 5:34 PM
Sarfira
Sarfira - avatar
+ 1
Arnesh thanks ! You are savior.
7th Jul 2020, 5:41 PM
Sarfira
Sarfira - avatar