擅长:python、mysql、java
<p>只需使用string类的<code>replace</code>方法:</p>
<pre class="lang-python prettyprint-override"><code>message_string = "This is a message"
print message_string.replace(" ", "\ ")
</code></pre>
<p>退货:</p>
^{pr2}$
<p>见<a href="http://docs.python.org/library/string.html#string.replace" rel="noreferrer">Python string.replace documentation</a>。在</p>