title: Does the len() built-in function iterates through the collection to calculate its length, or does it access a collection's attribute?
body: <p>Python has many <a href="https://docs.python.org/2/library/functions.html" rel="noreferrer">built-in functions</a>, and <code>len()</code> is one of them.</p>
  
  <blockquote>
    <p>Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).</p>
  </blockquote>
  
  <p>If collections and sequences are objects, they could hold a <code>length</code> attribute that can be updated every time something changes. Accessing this attribute would be a fast way to retrieve the collection's length. </p>
  
  <p>Another approach is to iterate through the collection and count the number of items on the fly.</p>
  
  <p>How does <code>len()</code> calculates said length? Through iteration or attribute access? One, none, both, other approaches?</p>