title: Why is cmp( ) useful?
body: <p>According to the <a href="http://docs.python.org/2/library/functions.html#cmp" rel="nofollow noreferrer">doc</a> and this <a href="http://www.tutorialspoint.com/python/number_cmp.htm" rel="nofollow noreferrer">tutorial</a>,</p>
  
  <p><code>cmp() returns -1 if x &lt; y</code> </p>
  
  <p>and </p>
  
  <p><code>cmp() returns 0 if  x == y</code> </p>
  
  <p>and </p>
  
  <p><code>cmp() returns 1 if  x &gt; y</code> </p>
  
  <p>The tutorial also said that</p>
  
  <blockquote>
    <p>cmp() returns the sign of the difference of two numbers</p>
  </blockquote>
  
  <p>I don't really get what  <em>sign of the difference of two numbers</em> means. Doesn't that mean that it returns a value when the sign of numbers aren't equal? Since...</p>
  
  <pre><code>cmp(80, 100) :  -1      # both have positive sign.
  cmp(180, 100) :  1      # both also have positive sign.
  cmp(-80, 100) :  -1
  cmp(80, -100) :  1
  </code></pre>
  
  <p>**Note: code from the tutorial.*</p>
  
  <p>Despite my confusion in sign differences, I can't really think of why do we need a built-in function to return a value of -1 when x &lt; y. </p>
  
  <p>Isn't the function <strong><code>cmp( )</code></strong> easily implemented ? Is there any reason why Python creators keep <code>cmp( )</code> function, or is there any hidden usage of this Python's <strong><code>cmp( )</code></strong> function ?</p>