Escape double quote in a String
To escape double quote character in a string in Python, when the string is created using double quotes, place a backslash character before the double quote character inside the string.
In the following example,
Welcome "Arjun" is string value. We escape the double quote characters inside the string, as shown in the following.
In the following program, we create a string
message, with double quote character escaped using backslash character, and print this string to console output.
message = "Welcome \"Arjun\"" print(message)Try Online
If the string is defined using single quotes, then there is no need to escape a double quote. The double quote in this scenario is a valid character.
message = 'Welcome "Arjun"' print(message)Try Online
In this Python Tutorial, we learned how to escape a double quote character inside a string, using backslash character.