list vs tuple

Alex Martelli aleaxit at yahoo.com
Wed Mar 28 14:41:29 EST 2001


"Rikard Bosnjakovic" <bos at hack.org> wrote in message
news:3AC1F93A.BAC9E34B at hack.org...
> deadmeat wrote:
>
> > so is that the only difference?
>
> Both are sequences, but tuples are "read-only", that's the only
> difference (except for the in-place-methods which requires mutability).

Actually, tuples have NO methods -- including those that would
require no mutability at all:

D:\pybridge\pybr>python
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> dir([])
['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
'sort']
>>> dir(())
[]
>>>

Note the lack of 'count' and 'index', which do not mutate a list
when applied to it, but are still missing from tuples.


Alex







More information about the Python-list mailing list