tuple question

Stephen Hansen stephen at cerebralmaelstrom.com
Wed Jun 14 03:08:51 EDT 2000


    This is a [insert descriptive word here] answer to your [insert
descriptive word here] question. I don't actually know the answer, but I can
guess at a couple possibilities based on the observation of the differences
between Python's lists and tuple's.

    A Tuple is of a fixed length, the length it was when it was created. A
list is of a dynamic length -- its actual size, I believe, from a memory-ish
standpoint, that lists are actually larger then they appear to be in the
Python environment. On the C level, my understanding from reading various
posts is that the list allocates additinoal memory for elements which may be
added in later, so that it doesn't have to allocate One Piece Of Memory
every time an element is added.
    A Tuple is immutable. Once created, with its given values, it can not be
changed. a = (1,2,3) can not have a[1] = 5 done. A list is mutable. You can
change the individual elements at any time.

    My unknowing guess? The overhead to create the truely 'dynamic' lists is
completely wasted in enough circumstances that it warrented making an array
which was fixed, in both size, and content.

    No clue if i'm right, but when I first came to Python, the whole concept
of an immutable array confused me enough that this is what my mind decided
Must Be The Right Answer (So, thus, it made me feel better about using them
:))

--S
etoffi <etoffi at softhome.net> wrote in message
news:3947255E.7CF77923 at softhome.net...
> *** post for free via your newsreader at post.newsfeeds.com ***
>
> admittedly this is a very [insert descriptive word here] question to ask,
but
> what is a tuple and why is it used (as opposed to an array, etc).  i
suppose the
> answer could be found in some comp sci book somewhere, but i dont have
access to
> those books.
>
> ps: i know:
>
> (x, y) = point.get()
>
> i just want to know what was the reason for creating/using tuples, more
from a
> language implementor standpoint than a witing-a-program-in-Python
standpoint...
>
> --
> Hopefully somebody will understand what I'm trying to say
>
>   **** Post for FREE via your newsreader at post.newsfeeds.com ****
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> *** Newsfeeds.com - The #1 Usenet Newsgroup Service on The Planet! ***
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>   http://www.newsfeeds.com     |         http://www.newsfeeds.com
>                                  |
> * Anonymous posting server!      | * Totally Uncensored!
> * SUPER Servers!                 | * Over 80,000 Newsgroups!
> * BINARIES ONLY Servers!         | * 16 seperate Newsgroup Servers!
> * SPAM FILTERED Server!          | * Instant access!
> * ADULT ONLY Server!             | * Multiple OC 3's and OC 12's!
> * MP3 ONLY Server!               | * 99% Article Completion!
> * MULTIMEDIA ONLY Server!        | * Months of Retention!
> * 7 UNCENSORED Newsgroup Servers | * Lightning FAST downloads!
>                                  |
>   http://www.newsfeeds.com       |         http://www.newsfeeds.com
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>         **** Point your newsreader to post.newsfeeds.com ****
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=





More information about the Python-list mailing list