vs. ()
bozon at natur.cuni.cz
Tue Mar 14 16:46:07 CET 2000
On 14 Mar 2000, Duncan Booth wrote:
> bozon at natur.cuni.cz (Michal Bozon) wrote in
> <Pine.OSF.4.10.10003141358100.31983-100000 at prfdec.natur.cuni.cz>:
> >Could anyone tell me the difference between tuples and lists? (except from
> >that a list has few methods (append, extend, remove...) and tuple
> >>>> l = [1, 2, 3]
> >>>> t = (1, 2, 3)
> >>>> l
> >>>> t
> Basically a tuple may not be modified after it is created but a list may
> be changed by anything that can refer to it.
> When you pass a list to some random function, the function may or may not
> change the list in situ. If you pass in a tuple, you can assume that the
> same tuple is available on return no matter what the function did.
> Also (for the same reason), you can use a tuple but not a list as a
> dictionary key.
So.. conclusion is: tuple is an immutable type but list is a mutable type?
More information about the Python-list