title: How is the method __lt__ invoked and processed by calling the method sort() in Python?
body: <p>Executing this code:</p>
  
  <pre><code>class Person(object):
  
      def __init__(self, name):
          self.name = name
          try:
              lastBlank = name.rindex(' ')
              self.lastName = name[lastBlank+1:]
          except:
              self.lastName = name
  
      def __lt__(self, other):
          if self.lastName == other.lastName:
              return self.name &lt; other.name
          return self.lastName &lt; other.lastName
  
      def __str__(self):
          return self.name
  
  me = Person('Michael Guttag')
  him = Person('Barack Hussein Obama')
  her = Person('Madonna')
  pList = [me, him, her]
  pList.sort() #invoke __lt__()
  for p in pList:
      print p
  </code></pre>
  
  <p>and it outputs:</p>
  
  <pre><code>Michael Guttag
  Madonna
  Barack Hussein Obama
  </code></pre>
  
  <p>In the book where it exemplifies class and operator overloading (or polymorphism) it says: 
  In addition to providing the syntactic convenience of writing infix expressions that use <code>&lt;</code>, this overloading provides automatic access to any polymorphic method defined using <code>__lt__</code>. The built-in method sort is one such method. So, for example, if <code>pList</code> is a list composed of elements of type <code>Person</code>, the call <code>pList.sort()</code> will sort that list using the <code>__lt__</code> method defined in class <code>Person</code>.</p>
  
  <p>I don't understand how <code>sort()</code> is a polymorphic method (actually the concept of polymorphism is still unclear to me after lots of researching), and how the method <code>__lt__</code> does the sorting to give such an output. I need a step-by-step guide. Thank you!</p>