DEV Community

Max Angelo Perin (ᜋᜃᜐ)
Max Angelo Perin (ᜋᜃᜐ)

Posted on

Answer: replace double quotes with '\"' in python

Try this:

print l.replace('"','\\"')

'\"' doesn't mean anything special to Python, so you needn't to add \ before ",if you run

print l.replace('\"', '\\"'),you will get a single backslash too.

Actually what you are seeing is the representation of the string, it's added by repr() method.Python represents…

Discussion (0)