title: Python: Usable Max and Min values
body: <p>Python 2.x allows heterogeneous types to be compared. </p>
  
  <p>A useful shortcut (in Python 2.7 here) is that <code>None</code> compares smaller than any integer or float value:</p>
  
  <pre><code>&gt;&gt;&gt; None &lt; float('-inf') &lt; -sys.maxint * 2l &lt; -sys.maxint
  True
  </code></pre>
  
  <p>And in Python 2.7 an empty tuple <code>()</code> is an infinite value:</p>
  
  <pre><code>&gt;&gt;&gt; () &gt; float('inf') &gt; sys.maxint
  True
  </code></pre>
  
  <p>This shortcut is useful when one might sort a mixed list of ints and floats and want to have an absolute minimum and maximum to reference.  </p>
  
  <p>This shortcut has been removed in Python 3000 however (this is Python 3.2):</p>
  
  <pre><code>&gt;&gt;&gt; None &lt; 0
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: unorderable types: NoneType() &lt; int()
  </code></pre>
  
  <p>Furthermore, Python3000 <a href="http://docs.python.org/release/3.1.5/whatsnew/3.0.html#integers" rel="noreferrer">has removed</a> <code>sys.maxint</code> on the theory that all ints promote to longs and the limit no longer applies. </p>
  
  <p><a href="http://www.python.org/dev/peps/pep-0326/" rel="noreferrer">PEP 326</a>, A Case for Top and Bottom Values, advanced a reference min and max in Python. The new ordering behavior <a href="http://docs.python.org/release/3.1.5/whatsnew/3.0.html#ordering-comparisons" rel="noreferrer">documented</a>. </p>
  
  <p>Since PEP 326 was rejected, what are useful, useable definitions for a min and max value that work with integers and floats and longs on Python 2X and Python 3000? </p>
  
  <p><strong>Edit</strong></p>
  
  <p>Several answers are along the lines of "just use maxv=float('inf')"... The reason I am thinking, however remote the possibility, is this:</p>
  
  <pre><code>&gt;&gt;&gt; float(2**5000)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  OverflowError: long int too large to convert to float 
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>&gt;&gt;&gt; cmp(1.0**4999,10.0**5000)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  OverflowError: (34, 'Result too large')
  </code></pre>
  
  <p>Yet:</p>
  
  <pre><code>&gt;&gt;&gt; () &gt; 2**5000
  True
  </code></pre>
  
  <p>In order to cmp to a float value, <code>float('inf')</code>, the long value would need to be converted to a float and the conversion would cause an <code>OverflowError</code>...</p>
  
  <p><strong>Conclusion</strong></p>
  
  <p>Thank you everyone for your answers and comments. I picked TryPyPy's <a href="https://stackoverflow.com/a/10577337/455276">answer</a> because it seemed most inline with what I was asking: an absolute greatest and absolute least value as described in the Wikipedia <a href="http://en.wikipedia.org/wiki/Infinity#Computing" rel="noreferrer">entry on infinity.</a> </p>
  
  <p>With this question, I learned that a long or int value is not converted to a float in order to complete the comparison of <code>float('inf') &gt; 2**5000</code>. I did not know that.</p>