擅长:python、mysql、java
<p>当<code>more_stuff</code>为空时,<code>len(more_stuff)=0</code>,<code>pop()</code>仍将工作。</p>
<p>使用<code>list</code>作为条件,如果列表为空,则bool值为<code>False</code></p>
<pre><code>more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana",
"Girl", "Boy"]
new_list = []
while more_stuff:
stuff = more_stuff.pop()
print ("Adding: ", stuff)
new_list.append(stuff)
</code></pre>
<blockquote>
<p>Any object can be tested for truth value, for use in an if or while
condition or as operand of the Boolean operations below. The following
values are considered false:</p>
<ul>
<li>None</li>
<li>False</li>
<li>zero of any numeric type, for example, 0, 0.0, 0j.</li>
<li>any empty sequence, for example, '', (), [].</li>
<li>any empty mapping, for example, {}.</li>
<li>instances of user-defined classes, if the class defines a <strong>bool</strong>() or <strong>len</strong>() method, when that method returns the integer zero or bool value False.</li>
</ul>
</blockquote>