<p>In many places, <code>(1,2,3)</code> (a tuple) and <code>[1,2,3]</code> (a list) can be used interchangeably.</p>

<p>When should I use one or the other, and why?</p>

[{'answer_id': 1987, 'author': 'sparkes', 'author_id': 269, 'author_profile': 'https://Stackoverflow.com/users/269', 'pm_score': 5, 'selected': False, 'text': '<p>The list <code>[1,2,3]</code> is dynamic and flexible but that flexibility comes at a speed cost.</p>\n\n<p>The tuple <code>(1,2,3)</code> is fixed (immutable) and therefore faster.</p>\n'}, {'answer_id': 2277, 'author': 'Joe Shaw', 'author_id': 156, 'author_profile': 'https://Stackoverflow.com/users/156', 'pm_score': 6, 'selected': True, 'text': '<p>From the <a href="http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types" rel="noreferrer">Python FAQ</a>:</p>\n<blockquote>\n<p>Lists and tuples, while similar in many respects, are generally used in fundamentally different ways. Tuples can be thought of as being similar to Pascal records or C structs; they\'re small collections of related data which may be of different types which are operated on as a group. For example, a Cartesian coordinate is appropriately represented as a tuple of two or three numbers.</p>\n<p>Lists, on the other hand, are more like arrays in other languages. They tend to hold a varying number of objects all of which have the same type and which are operated on one-by-one.</p>\n</blockquote>\n<p>Generally by convention you wouldn\'t choose a list or a tuple just based on its (im)mutability.  You would choose a tuple for small collections of completely different pieces of data in which a full-blown class would be too heavyweight, and a list for collections of any reasonable size where you have a homogeneous set of data.</p>\n'}, {'answer_id': 4595, 'author': 'HS.', 'author_id': 618, 'author_profile': 'https://Stackoverflow.com/users/618', 'pm_score': 4, 'selected': False, 'text': "<p>Tuples are a quick\\flexible way to create <em>composite</em> data-types.\nLists are containers for, well, lists of objects.</p>\n\n<p>For example, you would use a List to store a list of student details in a class.</p>\n\n<p>Each student detail in that list may be a 3-tuple containing their roll number, name and test score.</p>\n\n<pre><code>`[(1,'Mark',86),(2,'John',34)...]`\n</code></pre>\n\n<p>Also, because tuples are immutable they can be used as keys in dictionaries.</p>\n"}, {'answer_id': 5719, 'author': 'JSN', 'author_id': 108465, 'author_profile': 'https://Stackoverflow.com/users/108465', 'pm_score': 2, 'selected': False, 'text': '<p>As others have mentioned, Lists and tuples are both containers which can be used to store python objects. Lists are extensible and their contents can change by assignment, on the other hand tuples are immutable.</p>\n\n<p>Also, lists cannot be used as keys in a dictionary whereas tuples can.</p>\n'}, {'answer_id': 5746, 'author': 'Michael Neale', 'author_id': 699, 'author_profile': 'https://Stackoverflow.com/users/699', 'pm_score': 2, 'selected': False, 'text': '<p>If you can find a solution that works with tuples, use them, as it forces immutability which kind of drives you down a more functional path. You almost never regret going down the functional/immutable path.</p>\n'}, {'answer_id': 12454, 'author': 'cnu', 'author_id': 1448, 'author_profile': 'https://Stackoverflow.com/users/1448', 'pm_score': 2, 'selected': False, 'text': '<p>Whenever I need to pass in a collection of items to a function, if I want the function to not change the values passed in - I use tuples. </p>\n\n<p>Else if I want to have the function to alter the values, I use list. </p>\n\n<p>Always if you are using external libraries and need to pass in a list of values to a function and are unsure about the integrity of the data, use a tuple. </p>\n'}, {'answer_id': 12557, 'author': 'jcsalterego', 'author_id': 1416, 'author_profile': 'https://Stackoverflow.com/users/1416', 'pm_score': 3, 'selected': False, 'text': '<p>The notion of tuples are highly expressive:</p>\n\n<ul>\n<li><p>Pragmatically, they are great for packing and unpacking values (<code>x,y=coord</code>).</p></li>\n<li><p>In combination with dictionaries (hash tables), they allow forms of mapping that would otherwise require many levels of association.  For example, consider marking that (x,y) has been found.</p>\n\n<pre><code>// PHP\nif (!isset($found[$x])) {\n    $found[$x] = Array();\n    $found[$x][$y] = true;\n} else if (!isset($found[$x][$y])) {\n    $found[$x][$y] = true;\n}\n\n# Python\nfound[(x,y)] = True # parens added for clarity\n</code></pre></li>\n<li><p>Lists should be used with the expectation of operations on its contents (hence the various mentions of immutability).  One will want to pop, push, splice, slice, search, insert before, insert after, etc with a list.</p></li>\n<li><p>Tuples should be a low-level representation of an object, where simple comparisons are made, or operations such as extracting the n\'th element or n elements in a predictable fashion, such as the coordinates example given earlier.</p></li>\n<li><p>Lastly, lists are not hashable, so the type of mapping done with dictionaries (hash tables in Perl, associative arrays in PHP) must be done with tuples.</p>\n\n<p>Here\'s a simple example of tuples and dictionaries, together at last:</p>\n\n<pre><code>"""\ncouple is a tuple of two people\ndoesLike is a dictionary mapping couples to True or False\n"""\ncouple = "john", "jane"\ndoesLike = dict()\ndoesLike[couple] = True\ndoesLike["jane", "john"] = False # unrequited love :\'(\n</code></pre></li>\n</ul>\n'}, {'answer_id': 6477369, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p><code>[1, 2, 3]</code> is a list in which one can add or delete items.<br>\n<code>(1, 2, 3)</code> is a tuple in which once defined, modification cannot be done.</p>\n'}, {'answer_id': 26250158, 'author': 'Varun Chadha', 'author_id': 3408904, 'author_profile': 'https://Stackoverflow.com/users/3408904', 'pm_score': 2, 'selected': False, 'text': '<p><code>[1,2,3]</code> is a list.</p>\n\n<p><code>(1,2,3)</code> is a tuple and immutable.</p>\n'}, {'answer_id': 33058118, 'author': 'Serjik', 'author_id': 546822, 'author_profile': 'https://Stackoverflow.com/users/546822', 'pm_score': 2, 'selected': False, 'text': "<p>open a console and run python.\nTry this:</p>\n\n<pre><code>  &gt;&gt;&gt; list = [1, 2, 3]     \n  &gt;&gt;&gt; dir(list)\n    ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delsli\n    ce__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getit\n    em__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__',\n     '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__r\n    educe__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__'\n    , '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', \n'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']\n</code></pre>\n\n<p>As you may see the last on the last line list have the following methods:\n<strong>'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'</strong></p>\n\n<p>Now try the same for tuple:</p>\n\n<pre><code>&gt;&gt;&gt; tuple = (1, 2, 3)\n&gt;&gt;&gt; dir(tuple)\n    ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__\n    format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__get\n    slice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__\n    lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__'\n    , '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']\n</code></pre>\n\n<p>Only <strong>'count' and 'index'</strong> from list methods appears here.</p>\n\n<p>This is because tuples are immutable and they don't support any modifications. Instead they are simpler and faster in internal implementation.</p>\n"}, {'answer_id': 35496153, 'author': 'Mark Skelton', 'author_id': 5641674, 'author_profile': 'https://Stackoverflow.com/users/5641674', 'pm_score': 0, 'selected': False, 'text': '<p><code>(1,2,3)</code> is a tuple while <code>[1,2,3]</code> is a list.  A tuple is an immutable object while a list is mutable.</p>\n'}, {'answer_id': 38062967, 'author': 'Mestica', 'author_id': 2530378, 'author_profile': 'https://Stackoverflow.com/users/2530378', 'pm_score': 0, 'selected': False, 'text': '<p><code>(1,2,3)</code> is a tuple and <code>[1,2,3]</code> is a list. You either of the two represent sequences of numbers but note that tuples are immutable and list are mutable Python objects. </p>\n'}, {'answer_id': 44083156, 'author': 'RazyDave', 'author_id': 7935988, 'author_profile': 'https://Stackoverflow.com/users/7935988', 'pm_score': 2, 'selected': False, 'text': "<ul>\n<li>A tuple might represent a key in dictionary, because it's\nimmutable.</li>\n<li>Use lists if you have a collection of data that doesn't\nneed random access.</li>\n</ul>\n"}, {'answer_id': 49586164, 'author': 'Harry', 'author_id': 9070049, 'author_profile': 'https://Stackoverflow.com/users/9070049', 'pm_score': 2, 'selected': False, 'text': '<p>(1,2,3) and [1,2,3] can be used interchangeably in rare conditions. </p>\n\n<p>So (1,2,3) is a tuple and is immutable. Any changes you wish to make need to overwrite the object. </p>\n\n<p>[1,2,3] is a list and elements can be appended and removed. </p>\n\n<p>List has more features than a tuple. </p>\n'}, {'answer_id': 54570759, 'author': 'Python Experts', 'author_id': 10984637, 'author_profile': 'https://Stackoverflow.com/users/10984637', 'pm_score': 0, 'selected': False, 'text': '<p>(1,2,3)-tuple\n[1,2,3]-list\nlists are mutable on which various operations can be performed whereas tuples are immutable which cannot be extended.we cannot add,delete or update any element from a tuple once it is created.</p>\n'}, {'answer_id': 62503886, 'author': 'Rajat Arora', 'author_id': 8091455, 'author_profile': 'https://Stackoverflow.com/users/8091455', 'pm_score': 0, 'selected': False, 'text': "<p>a = (1,2,3) is a tuple which is immutable meaning you can't add anything into a\nb = [1,2,3] is a list in python which is immutable meaning you can make changes into 'b' either delete or add numbers into it.</p>\n"}, {'answer_id': 63479906, 'author': 'Sanmitha Sadhishkumar', 'author_id': 13827419, 'author_profile': 'https://Stackoverflow.com/users/13827419', 'pm_score': 0, 'selected': False, 'text': "<p>In simple words, lists are mutable whereas tuples are not. Hence, if you want to modify the elements in your program i.e., adding, deleting or altering elements, go for a list. But, if you don't want tat to happen i.e., may be for setting sequence in for loop, etc. go for a tuple</p>\n"}, {'answer_id': 69499270, 'author': 'Nirvana', 'author_id': 11064188, 'author_profile': 'https://Stackoverflow.com/users/11064188', 'pm_score': 0, 'selected': False, 'text': "<p><code>(1,2,3)</code> is immutable, so you can't add to it or change one of the items. In contrast, <code>[1,2,3]</code> is mutable, so you can add to it or change the items.</p>\n"}]
['https://Stackoverflow.com/questions/1983', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/116/']