[Tutor] Initializing Tupples
Joseph J. Strout
joe@strout.net
Fri, 27 Aug 1999 13:19:28 -0700
At 7:46 PM +0000 08/27/99, Jonathon wrote:
> Let's see if I understand the difference between lists and
> tuples.
>
> Once a Tuple is created, it can not be changed.
> Once a List is created, both it, and its contents can
> be changed --- increased, decreased etc.
Yep, that's it. (And, for the record, strings are just like tuples.)
> Example_Tuple = ( "joe", "curly", "moe" )
> and Example_Tuple retains that value for the duration
> of the program.
Well, not exactly -- you could easily rebind Example_Tuple to
something else, e.g.:
Example_Tuple = Example_Tuple[:2] # keep only the first two items
or
Example_Tuple = Example_Tuple + ("larry", "guido") # append two items
These work because the slice operator [:] or the addition operator
creates a *new* tuple, rather than modifying the old one in place;
and then this new tuple is bound to the name "Example_Tuple". Does
this make sense?
Cheers,
-- Joe
,------------------------------------------------------------------.
| Joseph J. Strout Biocomputing -- The Salk Institute |
| joe@strout.net http://www.strout.net |
`------------------------------------------------------------------'