擅长:python、mysql、java
<p>因为:</p>
<pre><code>>>> dict={}
>>> not dict
True
</code></pre>
<p>所以你可以这样检查:</p>
<pre><code>collection_a = {"hello":1,"bye":2}
if collection_a:
#do your stuff
print("not empty")
collection_a = {}
if collection_a:
print("dict is not empty")
</code></pre>
<p>如果要检查dict a或dict b,则:</p>
<pre><code>if collection_a or collection_b:
print("not empty")
</code></pre>