Python tuples are not just constant lists

Friday 28 April 2006This is over 18 years old. Be careful.

James Tauber mentions the distinction between lists and tuples in Python. I have to admit: I never made this distinction properly before. I didn’t even think of tuples as immutable lists. They were just the lists with parens, which made them less attractive, because it’s ugly to make one with a single element (that weird orphaned comma), and the parens don’t stand out from the rest of the code as well as square brackets do.

Of course, if you want to modify elements, you have to use a list, and if you want to provide a “list” of element to the string formatting operator, you have to use a tuple. Other than that, I never really thought about it.

Comments

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.