How to convert a normal string to escape characters in Python?

Question:

I want to convert string with all escape character.

Input

string = "Let's do this"
convert(string)

Output

Let's do this

Thank You!

Asked By: Anirudh Singh

||

Answers:

Your question is not clear. By escape character do you mean adding new line after certain characters or just want to add backslash do your string?

if you want to add backslash before ‘ character you can try below.

new_string = string.replace("'s", "\'s")
Answered By: Lanre
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.