擅长:python、mysql、java
<p>使用正则表达式。你知道吗</p>
<pre><code>import re
string='@!#word '
print(re.sub('[^A-Za-z]+', '', string))
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>word
</code></pre>
<hr/>
<p>如果需要去除侧面的特殊字符,请使用此选项。你知道吗</p>
<p><strong>例如:</strong></p>
<pre><code>import string
s='@!#word '
print(s.rstrip(string.punctuation).lstrip(string.punctuation))
</code></pre>
<p><strong>输出:</strong></p>
<pre><code>word
</code></pre>