<div class="gmail_quote">On Thu, Dec 15, 2011 at 6:56 PM, Ned Batchelder <span dir="ltr"><<a href="mailto:ned@nedbatchelder.com">ned@nedbatchelder.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
    On 12/15/2011 8:39 PM, Guido van Rossum wrote:
    <blockquote type="cite">
      <div class="gmail_quote">On Thu, Dec 15, 2011 at 5:16 PM, Terry
        Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div>On 12/15/2011 3:42 PM, Ned Batchelder wrote:<br>
            <br>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              This is another place where Python is inconsistent. We're
              told, "lists<br>
              are for homogenous sequences of varying length, like a C
              array; tuples<br>
              are for heterogenous aggregations of known length, like a
              C struct."<br>
            </blockquote>
            <br>
          </div>
          I have not been told that for several years, and I am pretty
          sure you will not find any such thing in the current docs. I
          consider it pretty much obsolete, as the differences that
          flowed from that idea are gone. In Python 3, tuples have all
          the non-mutating sequence methods that list does. The
          situation was much different in 1.4.<span></span><br clear="all">
        </blockquote>
        <div><br>
          I strongly disagree. Being immutable sequences (i.e.
          homogeneous) is a minor secondary role for tuples. Their
          primary role remains to hold a small bunch of heterogeneous
          values -- like namedtuple, but without needing forethought. A
          good example are dictionary items -- these are (key, value)
          pairs where for a given dict, the keys are all of the same
          type (or of a small set of related types) and ditto for the
          values, but the key type and the value types are unrelated.<br>
        </div>
      </div>
    </blockquote></div></div>
    Could you explain why the foo(*args) syntax creates args as a tuple
    rather than a list?<span class="HOEnZb"><font color="#888888"></font></span><br clear="all"></div></blockquote><div><br>It's a historical accident. In ABC, functions didn't have multiple arguments -- instead there was a single argument that was a tuple. If you go back way, way in Python's early history (before 1.0 I think) you'll find that arguments kind of worked the same way. Then an idiom developed to accept a variable number of arguments, in order to support default argument values (because Python's tuples, unlike ABC's, were sequences even then). This turned out to be awkward if you wanted 1 or 2 arguments (the 1-arg case had to be dealt with special because you'd receive a plain value instead of a tuple) and then the *args and arg=value syntax was invented. But because previously varargs had been tuples, we kept them tuples. (I think this was also in the days that you couldn't unpack a list -- but I'm not actually sure of that. I do know that tuple unpacking was always in the language.)<br>

</div></div><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br>