Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>None</code> is always less than any datatype in Python 2 (see <a href="http://hg.python.org/cpython/file/ab05e7dd2788/Objects/object.c#l778" rel="noreferrer"><code>object.c</code></a>).</p> <p>In Python 3, this was changed; now doing comparisons on things without a sensible natural ordering results in a <code>TypeError</code>. From the <strong><a href="https://docs.python.org/3/whatsnew/3.0.html#ordering-comparisons" rel="noreferrer">3.0 "what's new" updates</a></strong>:</p> <blockquote> <p>Python 3.0 has simplified the rules for ordering comparisons:</p> <p>The ordering comparison operators (<code>&lt;</code>, <code>&lt;=</code>, <code>&gt;=</code>, <code>&gt;</code>) raise a <code>TypeError</code> exception when the operands don’t have a meaningful natural ordering. Thus, expressions like: <code>1 &lt; ''</code>, <code>0 &gt; None</code> or <code>len &lt;= len</code> are no longer valid, and e.g. <code>None &lt; None</code> raises <code>TypeError</code> instead of returning <code>False</code>. A corollary is that sorting a heterogeneous list no longer makes sense – all the elements must be comparable to each other. Note that this does not apply to the <code>==</code> and <code>!=</code> operators: objects of different incomparable types always compare unequal to each other.</p> </blockquote> <p>This upset some people since it was often handy to do things like sort a list that had some <code>None</code> values in it, and have the <code>None</code> values appear clustered together at the beginning or end. <strong><a href="http://markmail.org/message/qztbun75kcsewzuk#query:none%20comparability%20python+page:1+mid:tmxfw326w3efme7w+state:results" rel="noreferrer">There was a thread on the mailing list about this</a></strong> a while back, but the ultimate point is that Python 3 tries to avoid making arbitrary decisions about ordering (which is what happened a lot in Python 2).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload