擅长:python、mysql、java
<p>使用<code>str.split([sep[, maxsplit]])</code>而不使用<code>sep</code>或<code>sep=None</code>:</p>
<p>来自<a href="http://docs.python.org/2/library/stdtypes.html#str.split" rel="noreferrer">docs</a>:</p>
<blockquote>
<p>If <code>sep</code> is not specified or is <code>None</code>, a different splitting algorithm is
applied: runs of consecutive whitespace are regarded as a single
separator, and the result will contain no empty strings at the start
or end if the string has leading or trailing whitespace.</p>
</blockquote>
<p><strong>演示:</strong></p>
<pre><code>>>> myString.split()
['I', 'want', 'to', 'Remove', 'all', 'white', 'spaces,', 'new', 'lines', 'and', 'tabs']
</code></pre>
<p>使用返回列表中的<code>str.join</code>获取此输出:</p>
<pre><code>>>> ' '.join(myString.split())
'I want to Remove all white spaces, new lines and tabs'
</code></pre>