Tuple vs List: Whats the difference?

Hendrik van Rooyen mail at microcorp.co.za
Thu Jul 12 02:17:07 EDT 2007


"Shafik" <s...3 at gmail.com> wrote:


> Hello folks,
> 
> I am an experienced programmer, but very new to python (2 days). I
> wanted to ask: what exactly is the difference between a tuple and a
> list? I'm sure there are some, but I can't seem to find a situation
> where I can use one but not the other.

Welcome to Python.

>From a practical point of view, use lists - you will get exceptions
if you use a list where a tuple is required, such as a key in a dict,
and other more obscure cases.

The philosophical differences - "tuple as struct" vs "list as collection"
argument, makes no practical difference - you can use a list in the same 
structured way if you want, and lists have more nice methods as they 
are not immutable as tuples are.

Google this Group for "Index" to see some flame wars.

hth - Hendrik




More information about the Python-list mailing list