擅长:python、mysql、java
<p>不要用这句话来搪塞你,用一个好的旧的理解列表:</p>
<pre><code>text = raw_input('Enter text') #or input(...) if you're using python 3.X
number_of_non_spaces = len([i for i in text if i != " "])
number_of_spaces = len(text) - number_of_non_spaces
</code></pre>