擅长:python、mysql、java
<p>最好的方法是检查有问题项的数据类型。您可以使用:</p>
<pre><code>if isinstance(item, list):
...
</code></pre>
<p>以及:</p>
<pre><code>if isinstance(item, str):
...
</code></pre>
<p>对于字符串,如果愿意,可以使用1作为长度。请注意,使用<code>isinstance(item, dtype)</code>比使用<code>type(item) == dtype</code>更好,因为它将自动处理子类类型。你知道吗</p>