Lists vs tuples (newbie)

Szabolcs szhorvat at gmail.com
Mon May 21 08:31:44 EDT 2007


Thanks for all the replies!

Phoe6 wrote:
> 1) Return values from a function.  When you return multiple values
> from a function. You store them as a tuple and access them
> individually rather then in the list, which bear the danger of being
> modified.
> Look up the standard library itself and you will find many instances.
> 
> (cin, cout, cerr) = os.popen3('man man')
> 
> If you had the above as list, then you might end up spoiling things
> knowingly/unknowingly.

Could you please elaborate on this (or give an explicit example how 
might one do something bad unknowingly when returning multiple values in 
a list)?

Should I think of tuples simply as a safeguard and reminder (because I 
consciously use them for different thing than lists, as the faq 
suggests)? Something similar to C++'s "const" (i.e. not strictly 
necessary but useful for avoiding bugs)?

Szabolcs



More information about the Python-list mailing list