擅长:python、mysql、java
<p>它的工作原理是这样的<sup>1</sup>。在</p>
<pre><code>>>> float() == long() == int() < dict() < list() < str() < tuple()
True
</code></pre>
<p>数字比容器小。数字类型将转换为通用类型,并根据其数值进行比较。容器按名称的字母值进行比较。<sup>2</sup></p>
<p>从<a href="http://docs.python.org/library/stdtypes.html#comparisons" rel="nofollow">docs</a>:</p>
<blockquote>
<p>CPython implementation detail: Objects of different types except numbers are ordered by >their type names; objects of the same types that don’t support proper comparison are >ordered by their address.</p>
</blockquote>
<p>不同内置类型的对象按其类型名称的字母顺序进行比较<code>int</code>以“i”开头,<code>str</code>以<code>s</code>开头,因此任何<code>int</code>都比任何{<cd2>}小。</strike>。在</p>
<ol>
<li>我不知道。
<ul>
<li>醉酒的主人。在</li>
</ul></li>
<li>这意味着在内置类型上引入了形式化的顺序。
<ul>
<li>它指的是任意命令。在</li>
<li>没有</li>
</ul></li>
<li>不需要。字符串和unicode对象在这方面是相同的。试试看。在</li>
</ol>
<p>回应关于<code>long < int</code>的评论</p>
^{pr2}$
<p>不过,您可能是指那些类型的值,在这种情况下,数字比较适用。在</p>
<p><sup>1所有这些都是在Python2.6.5上实现的</sup></p>
<p>感谢克朗帮我解决了这个问题。我以前从没想过要把一个数字和一个<code>dict</code>作比较,而数字的比较是如此明显,很容易被忽视的事情之一。</sup></p>