[Python-Dev] Ridiculously minor tweaks?

Barry A. Warsaw barry@python.org
Wed, 12 Mar 2003 09:23:29 -0500


>>>>> "GvR" == Guido van Rossum <guido@python.org> writes:

    GvR> I always think of the type of a list as "list of T" while I
    GvR> think of a tuple's type as "tuple of length N with items of
    GvR> types T1, T2, T3, ..., TN".  So [1, 2] and [1, 2, 3] are both
    GvR> "list of int" (and "list of Number" and "list of Object", of
    GvR> course) while ("hello", 42) is a "2-tuple with items str and
    GvR> int" and (42, "hello", 3.14) is a "3-tuple with items int,
    GvR> str, float".

Of course (1, 2, 3) fits under that description, where, just by chance
<wink> T1 == T2 == T3.

But one of the ways I think about it is the tuple's relationship to
argument and return passing.  It's the tuple that's used when multiple
values are returned from a function and they are almost always
heterogeneous.  And while lists can be used for unpacking sequences, I
tend to think of tuples when I want record types, e.g.

    rec = magic(blah)
    length, prefix, interface = rec

-Barry