Python: Replace Slashes
<p>I got some unicode with percent signs I want to change to backslashes. I know you need an additional backslash as an escape sequence, but when I did this <code>replace()</code> gave me two backslashes:</p>

<pre><code>&gt;&gt;&gt; s ="%20%u200F%u05D1%u05E8%u05DB%u05EA%u200F%20%u200F%u05D4%u05E8%u05D9%u05D7%u200F%20%u200F%u05D5%u05D1%u05E8%u05DB%u05EA%u200F%20%u200F%u05D4%u05D5%u05D3%u05D0%u05D4"
&gt;&gt;&gt; s.replace("%","\")
File "&lt;stdin&gt;", line 1
s.replace("%","\")                  
SyntaxError: EOL while scanning string literal

&gt;&gt;&gt; s.replace("%","\\")
'\\20\\u200F\\u05D1\\u05E8\\u05DB\\u05EA\\u200F\\20\\u200F\\u05D4\\u05E8\\u05D9\\u05D7\\u200F\\20\\u200F\\u05D5\\u05D1\\u05E8\\u05DB\\u05EA\\u200F\\20\\u200F\\u05D4\\u05D5\\u05D3\\u05D0\\u05D4'
</code></pre>

<p>The <code>'r'</code> qualifyer isn't working either. Any ideas?</p>

<p>Just like you have to type two backslashes to enter one, Python, when displaying a quoted string, displays two to indicate it is a literal backslash.  <code>'\\x41'</code> is four characters, <code>'\x41'</code> is one (equivalent to <code>'A'</code>).  It's a debugging feature so you can see unprintable characters, for example, and tell the difference.</p>

<pre><code>&gt;&gt;&gt; a = '\xa0\\xa0'
&gt;&gt;&gt; a
'\xa0\\xa0'
&gt;&gt;&gt; print(a)
Â \xa0
</code></pre>

python string