title: Using len() and def __len__(self): to build a class
body: <p>Just curious,</p>
  
  <p>Is there any difference (advantages and disadvantages) between using <code>len()</code> or <code>def __len__()</code> when I build a class? And which is the best Python style?</p>
  
  <pre><code>   class foo(object):
        def __init__(self,obs=[])
           self.data = obs
           self.max = max(obs)
           self.min = min(obs)
           self.len = len(obs)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>   class foo(object):
        def __init__(self,obs=[])
           self.data = obs
           self.max = max(obs)
           self.min = min(obs)
        def __len__(self):
           return len(self.data)
  </code></pre>