擅长:python、mysql、java
<p>只需调用<code>str.strip</code>一次:</p>
<pre><code>In [6]: import string
In [7]: "\t [[ dwarf ]]] \n".strip("[]" + string.whitespace)
Out[7]: 'dwarf'
</code></pre>
<p><a href="https://docs.python.org/3/library/string.html#string.whitespace" rel="nofollow">^{<cd2>}</a>是包含所有(ascii)空格字符的字符串。<code>S.strip("[]" + string.whitespace)</code>将剥离<code>[</code>、<code>]</code>和空格字符的所有组合。你知道吗</p>