Lists vs tuples (newbie)
Phoe6
orsenthil at gmail.com
Mon May 21 08:09:00 EDT 2007
On May 21, 4:48 pm, Szabolcs <szhor... at gmail.com> wrote:
> In what circumstances is it advantageous to use tuples instead of lists?
> Is there a difference in performance?
>
As you should not, tuples are immutable while lists are mutable. You
can think of all the scenarios where immutable datatype are required.
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.
2) Programming requirements arise when you have to deal with
persistent data.
HTH.
Senthil
http://uthcode.sarovar.org
More information about the Python-list
mailing list