() vs 
nanjundi at gmail.com
Wed Oct 14 19:21:27 CEST 2009
On Oct 14, 1:05 pm, mattia <ger... at gmail.com> wrote:
> Any particular difference in using for a simple collection of element ()
> over  or vice-versa?
> Thanks, Mattia
1 You can’t add elements to a tuple. Tuples have no append or extend
2 You can’t remove elements from a tuple. Tuples have no remove or
3 You can’t find elements in a tuple. Tuples have no index method.
4 You can, however, use in to see if an element exists in the tuple.
So what are tuples good for?
* 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.
* Remember I said that dictionary keys can be integers, strings,
and “a few other types”? Tuples are one of those types. Tuples can be
used as keys in a dictionary, but lists can’t.
* Tuples are used in string formatting, as we’ll see shortly.
More information about the Python-list