Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Chris Angelico rosuav at gmail.com
Wed Nov 25 08:44:38 EST 2015


On Thu, Nov 26, 2015 at 12:06 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> However, tuples are a way to represent records, groupings of related
> values, where the semantics of each value is determined by its position
> in the tuple. The members in a tuple are typically of different data
> types.
>
> Lists are collections of values. Typically, each member of list is of
> the same type.

This is a distinction I generally make. Putting it another way: a list
has the same meaning regardless of how many items are on it (for
instance, a shopping list is still a shopping list whether it has five
or fifty items on it), where a tuple is a package where each element
has a specific meaning (such as Cartesian coordinates; the difference
between the position (2,3) and the position (2,3,4) is not just that
there's "more position" in the second one - it's a drastically
different beast, living in three dimensions instead of two).

Nothing in the language enforces this, but the mutability of lists
does tend to align well with things that can grow and shrink, and the
immutability of tuples makes them more like strings or complex numbers
(in fact, a complex number is basically a tuple of two floats).

ChrisA



More information about the Python-list mailing list