<p>为什么<code>if from_unit ==unit[0]</code>会返回<code>found unit, in</code>?是不是<code>unit[0]==['cm',0.01]</code>?这不应该等于<code>in</code>,对吧?**</p>
<p><a href="https://i.stack.imgur.com/W10de.png" rel="nofollow noreferrer">Image</a></p>
<p>以下是我的代码:</p>
<pre><code>def converter(value, from_unit='cm',to_unit='m'):
units = [['m',1],['cm',0.01],['in',0.0254]]
if from_unit != units[0][0]:
print("conver to base unit")
for unit in units[1:]:
if from_unit == unit[0]:
print("found unit ", unit[0])
print(converter(10,'in','cm'))
</code></pre>