list vs tuple

Benjamin.Altman benjamin.altman at noaa.gov
Wed Mar 28 12:58:10 EST 2001


The Tutorial "Dive Into Python" (link from the python web site
http://www.python.org/doc/Intros.html or http://diveintopython.org/toc.html)
says:

1. Tuples are faster than lists. If you're defining a constant set of values
and all you're ever going to do with it is iterate through it, use a tuple
instead of a list...
2. Tuples are one of those types [that]... can be used as keys in a
dictionary, but lists can't.
3. Tuples are used in string formatting.

Also (same source):

  You can't add elements to a tuple. Tuples have no append or extend method.

  You can't remove elements from a tuple. Tuples have no remove or pop
method.
  You can't find elements in a tuple. Tuples have no index method.
  You can, however, use in to see if an element exists in the tuple.

regards,
Ben






deadmeat wrote:

> Whats the practical difference between a list[] and a tuple() ?
>
> A tuple seems to be a very basic list, so unless it's faster, what's the
> point of it?




More information about the Python-list mailing list