擅长:python、mysql、java
<p>要测试某个内容是否可iterable,可以使用<code>collection.abc</code>模块中的<a href="https://docs.python.org/3.4/library/collections.abc.html#collections.abc.Iterable" rel="nofollow">abstract base class</a>:</p>
<pre><code>isinstance(llist, collection.abc.Iterable)
</code></pre>
<p>请注意,Python为<a href="https://docs.python.org/3.4/glossary.html#term-iterable" rel="nofollow">iterable objects</a>定义了一个行为/协议,这可能不是您练习的目的,但是您可能会对遵守它感兴趣。你知道吗</p>