Recommended Video Course
Lists and Tuples in Python
Table of Contents
Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:Lists and Tuples in Python
Python lists and tuples are sequence data types that store ordered collections of items. While lists are mutable and ideal for dynamic, homogeneous data, tuples are immutable, making them suitable for fixed, heterogeneous data. Read on to compare tuples vs. lists.
By the end of this tutorial, you’ll understand that:
list()
constructor, which converts the tuple into a mutable list.In this tutorial, you’ll learn to define, manipulate, and choose between these two data structures. To get the most out of this tutorial, you should know the basics of Python programming, including how to define variables.
Get Your Code:Click here to download the free sample code that shows you how to work with lists and tuples in Python.
Take the Quiz: Test your knowledge with our interactive “Lists vs Tuples in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:
Interactive Quiz
Lists vs Tuples in PythonChallenge yourself with this quiz to evaluate and deepen your understanding of Python lists and tuples. You'll explore key concepts, such as how to create, access, and manipulate these data types, while also learning best practices for using them efficiently in your code.
In Python, a list is a collection of arbitrary objects, somewhat akin to anarray in many other programming languages but more flexible. To define a list, you typically enclose a comma-separated sequence of objects in square brackets ([]
), as shown below:
>>>colors=["red","green","blue","yellow"]>>>colors['red', 'green', 'blue', 'yellow']
In this code snippet, you define a list of colors usingstring objects separated by commas and enclose them in square brackets.
Similarly, tuples are also collections of arbitrary objects. To define a tuple, you’ll enclose a comma-separated sequence of objects in parentheses (()
), as shown below:
>>>person=("Jane Doe",25,"Python Developer","Canada")>>>person('Jane Doe', 25, 'Python Developer', 'Canada')
In this example, you define a tuple with data for a given person, including their name, age, job, and base country.
Up to this point, it may seem that lists and tuples are mostly the same. However, there’s an important difference:
Feature | List | Tuple |
---|---|---|
Is an ordered sequence | ✅ | ✅ |
Can contain arbitrary objects | ✅ | ✅ |
Can be indexed and sliced | ✅ | ✅ |
Can be nested | ✅ | ✅ |
Is mutable | ✅ | ❌ |
Both lists and tuples aresequence data types, which means they can contain objects arranged in order. You can access those objects using an integer index that represents their position in the sequence.
Even though both data types can contain arbitrary and heterogeneous objects, you’ll commonly use lists to store homogeneous objects and tuples to store heterogeneous objects.
Note: In this tutorial, you’ll see the terms homogeneous and heterogeneous used to express the following ideas:
You can perform indexing and slicing operations on both lists and tuples. You can also have nested lists and nested tuples or a combination of them, like a list of tuples.
The most notable difference between lists and tuples is that lists are mutable, while tuples are immutable. This feature distinguishes them and drives their specific use cases.
Essentially, a list doesn’t have a fixed length since it’s mutable. Therefore, it’s natural to use homogeneous elements to have some structure in the list. A tuple, on the other hand, has a fixed length so the position of elements can have meaning, supporting heterogeneous data.
In many situations, you’ll define alist
object using aliteral. A list literal is a comma-separated sequence of objects enclosed in square brackets:
>>>countries=["United States","Canada","Poland","Germany","Austria"]>>>countries['United States', 'Canada', 'Poland', 'Germany', 'Austria']
In this example, you create a list of countries represented by string objects. Because lists are ordered sequences, the values retain the insertion order.
Note: To learn more about thelist
data type, check out thePython’s list Data Type: A Deep Dive With Examples tutorial.
Alternatively, you can create new lists using thelist()
constructor:
>>>digits=list(range(10))>>>digits[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In this example, you use thelist()
constructor to define a list of digits using arange
object. In general,list()
can convert any iterable to a list.
That means that you can also use it to convert a tuple into a list:
>>>list((1,2,3))[1, 2, 3]
You can also create newlist
objects usinglist comprehensions. For example, the following comprehension builds a list of even digits:
>>>even_digits=[numberfornumberinrange(1,10)ifnumber%2==0]>>>even_digits[2, 4, 6, 8]
List comprehensions are powerful tools for creating lists in Python. You’ll often find them in Python code that runs transformations over sequences of data.
Finally, to create an empty list, you can use either an empty pair of square brackets or thelist()
constructor without arguments:
>>>[][]>>>list()[]
The first approach is arguably the most efficient and most commonly used. However, the second approach can be more explicit and readable in some situations.
Similar to lists, you’ll often create new tuples using literals. Here’s a short example showing a tuple definition:
>>>connection=("localhost","8080",3,"database.db")>>>connection('localhost', '8080', 3, 'database.db')
In this example, you create a tuple containing the parameters for a database connection. The data includes the server name, port, timeout, and database name.
Note: To dive deeper into thetuple
data type, check out thePython’s tuple Data Type: A Deep Dive With Examples tutorial.
Strictly speaking, to define a tuple, you don’t need the parentheses. The comma-separated sequence will be enough:
>>>contact="John Doe","john@example.com","55-555-5555">>>contact('John Doe', 'john@example.com', '55-555-5555')
In practice, you can define tuples without using a pair of parentheses. However, using the parentheses is a common practice because it improves the readability of your code.
Because the parentheses are optional, to define a single-item tuple, you need to use a comma:
>>>t=(2,)>>>type(t)<class 'tuple'>>>>t=(2)>>>type(t)<class 'int'>
In the first example, you create a tuple containing a single value by appending a comma after the value. In the second example, you use the parentheses without the comma. In this case, you create an integer value instead of a tuple.
You can also create new tuples using thetuple()
constructor:
>>>tuple(range(10))(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
In this example, you create a list of digits usingtuple()
. This way of creating tuples can be helpful when you’re working withiterators and need to convert them into tuples.
For example, you can convert a list into a tuple using thetuple()
constructor:
>>>tuple([1,2,3])(1, 2, 3)
Finally, to create empty tuples, you can use a pair of parentheses or calltuple()
without arguments:
>>>()()>>>tuple()()
The first approach is a common way to create empty tuples. However, usingtuple()
can be more explicit and readable.
Now that you know the basics of creating lists and tuples in Python, you’re ready to explore their most relevant features and characteristics. In the following section, you’ll dive into these features and learn how they can impact the use cases of lists and tuples in your Python code.
List and tuples are ordered sequences of objects. The order in which you insert the objects when you create a list or tuple is an innate characteristic. This order remains the same for that list or tuple’s lifetime:
>>>["mango","orange","apple"]['mango', 'orange', 'apple']>>>("Jane",25,"Norway")('Jane', 25, 'Norway')
In these examples, you can confirm that the order of items in lists and tuples is the same order you define when creating the list or tuple.
Lists and tuples can contain any Python objects. The elements of a list or tuple can all be the same type:
>>>[1,2,3,4,5][1, 2, 3, 4, 5]>>>(1,2,3,4,5)(1, 2, 3, 4, 5)
In these examples, you create a list of integer numbers and then a tuple of similar objects. In both cases, the contained objects have the same data type. So, they’re homogeneous.
The elements of a list or tuple can also be of heterogeneous data types:
>>>["Pythonista",7,False,3.14159]['Pythonista', 7, False, 3.14159]>>>("Pythonista",7,False,3.14159)('Pythonista', 7, False, 3.14159)
Here, your list and tuple contain objects of different types, including strings, integers, Booleans, and floats. So, your list and tuple are heterogeneous.
Note: Even though lists and tuples can contain heterogeneous or homogeneous objects, the common practice is to use lists for homogeneous objects and tuples for heterogeneous objects.
Lists and tuples can even contain objects like functions, classes, and modules:
>>>int<class 'int'>>>>len<built-in function len>>>>deffunc():...pass...>>>func<function func at 0x1053abec0>>>>importmath>>>math<module 'math' from '.../math.cpython-312-darwin.so'>>>>[int,len,func,math][ <class 'int'>, <built-in function len>, <function func at 0x1053abec0>, <module 'math' from '.../math.cpython-312-darwin.so'>]>>>(int,len,func,math)( <class 'int'>, <built-in function len>, <function func at 0x1053abec0>, <module 'math' from '.../math.cpython-312-darwin.so'>)
In these examples, the list and the tuple contain a class,built-in function, customfunction, and module objects.
Lists and tuples can contain any number of objects, from zero to as many as your computer’s memory allows. In the following code, you have a list and tuple built out of a range with a million numbers:
>>>list(range(1_000_000))>>>tuple(range(1_000_000))
These two lines of code will take some time to run and populate your screen with many, many numbers.
Finally, objects in a list or tuple don’t need to be unique. A given object can appear multiple times:
>>>["bark","meow","woof","bark","cheep","bark"]['bark', 'meow', 'woof', 'bark', 'cheep', 'bark']>>>("bark","meow","woof","bark","cheep","bark")('bark', 'meow', 'woof', 'bark', 'cheep', 'bark')
Lists and tuples can contain duplicated values like"bark"
in the above examples.
You can access individual elements in a list or tuple using the item’s index in square brackets. This is exactly analogous to accessing individual characters in a string. List indexing is zero-based, as it is with strings.
Consider the following list:
>>>words=["foo","bar","baz","qux","quux","corge"]
The indices for the elements inwords
are shown below:
Here’s the Python code to access individual elements ofwords
:
>>>words[0]'foo'>>>words[2]'baz'>>>words[5]'corge'
The first element in the list has an index of0
. The second element has an index of1
, and so on. Virtually everything about indexing works the same for tuples.
You can also use a negative index, in which case the count starts from the end of the list:
Index-1
corresponds to the last element in the list, while the first element is-len(words)
, as shown below:
>>>words[-1]'corge'>>>words[-2]'quux'>>>words[-len(words)]'foo'
Slicing also works with lists and tuples. For example, the expressionwords[m:n]
returns the portion ofwords
from indexm
to, but not including, indexn
:
>>>words[2:5]['baz', 'qux', 'quux']
Other features of slicing work for lists as well. For example, you can use both positive and negative indices:
>>>words[-5:-2]['bar', 'baz', 'qux']>>>words[1:4]['bar', 'baz', 'qux']>>>words[-5:-2]==words[1:4]True
Omitting the first index starts the slice at the beginning of the list or tuple. Omitting the second index extends the slice to the end of the list or tuple:
>>>words[:4]['foo', 'bar', 'baz', 'qux']>>>words[0:4]['foo', 'bar', 'baz', 'qux']>>>words[2:]['baz', 'qux', 'quux', 'corge']>>>words[2:len(words)]['baz', 'qux', 'quux', 'corge']>>>words[:4]+words[4:]['foo', 'bar', 'baz', 'qux', 'quux', 'corge']>>>words[:4]+words[4:]==wordsTrue
You can specify a stride—either positive or negative:
>>>words[0:6:2]['foo', 'baz', 'quux']>>>words[1:6:2]['bar', 'qux', 'corge']>>>words[6:0:-2]['corge', 'qux', 'bar']
The slicing operator ([:]
) works for both lists and tuples. You can check it out by turningwords
into a tuple and running the same slicing operations on it.
You’ve seen that an element in a list or tuple can be of any type. This means that they can contain other lists or tuples. For example, a list can contain sublists, which can contain other sublists, and so on, to arbitrary depth.
Consider the following example:
>>>x=["a",["bb",["ccc","ddd"],"ee","ff"],"g",["hh","ii"],"j"]
The internal structure of this list is represented in the diagram below:
In this diagram,x[0]
,x[2]
, andx[4]
are strings, each one character long:
>>>x[0],x[2],x[4]('a', 'g', 'j')
However,x[1]
andx[3]
are sublists or nested lists:
>>>x[1]['bb', ['ccc', 'ddd'], 'ee', 'ff']>>>x[3]['hh', 'ii']
To access the items in a sublist, append an additional index:
>>>x[1][0]'bb'>>>x[1][1]['ccc', 'ddd']>>>x[1][2]'ee'>>>x[1][3]'ff'
Here,x[1][1]
is yet another sublist, so adding one more index accesses its elements:
>>>x[1][1][0]'ccc'>>>x[1][1][1]'ddd'
There’s no limit to the depth you can nest lists this way. However, deeply nested lists or tuples can be hard to decipher in an indexing or slicing context.
The built-inlist
class provides amutable data type. Being mutable means that once you create alist
object, you can add, delete, shift, and move elements around at will. Python provides many ways to modify lists, as you’ll learn in a moment. Unlike lists, tuples areimmutable, meaning that you can’t change a tuple once it has been created.
Note: To learn more about mutability and immutability in Python, check out thePython’s Mutable vs Immutable Types: What’s the Difference? tutorial.
You can replace or update a value in a list by indexing it on the left side of anassignment statement:
>>>letters=["A","B","c","d"]# A list>>>letters[2]="C">>>letters['A', 'B', 'C', 'd']>>>letters[-1]="D">>>letters['A', 'B', 'C', 'D']
In this example, you create a list of letters where some letters are in uppercase while others are in lowercase. You use an assignment to turn the lowercase letters into uppercase letters.
Now, because tuples are immutable, you can’t do with a tuple what you did in the above example with a list:
>>>letters=("A","B","c","d")# A tuple>>>letters[2]="C"Traceback (most recent call last):...TypeError:'tuple' object does not support item assignment
If you try to update the value of a tuple element, you get aTypeError
exception because tuples are immutable, and this type of operation isn’t allowed for them.
You can also use thedel
statement to delete individual items from a list. However, that operation won’t work on tuples:
>>>fruits=["apple","orange","mango","grape"]>>>delfruits[0]# Remove apple>>>fruits['orange', 'mango', 'grape']>>>person=("John Doe",35,"Web Dev")>>>delperson[1]# Try to remove the age valueTraceback (most recent call last):...TypeError:'tuple' object doesn't support item deletion
You can remove individual elements from lists using thedel
statement because lists are mutable, but this won’t work with tuples because they’re immutable.
Note: To learn more about thedel
statement, check out thePython’sdel
: Remove References From Scopes and Containers tutorial.
What if you want to change several elements in a list at once? Python allows this operation with aslice assignment, which has the following syntax:
a_list[m:n]=<iterable>
Think of aniterable as a container of multiple values like a list or tuple. This assignment replaces the specified slice ofa_list
with the content of<iterable>
:
>>>numbers=[1,2,3,0,0,0,7]>>>numbers[3:6]=[4,5,6]>>>numbers[1, 2, 3, 4, 5, 6, 7]
In this example, you replace the0
values with the corresponding consecutive numbers using a slice assignment.
It’s important to note that the number of elements to insert doesn’t need to be equal to the number of elements in the slice. Python grows or shrinks the list as needed. For example, you can insert multiple elements in place of a single element:
>>>numbers=[1,2,3,7]>>>numbers[3:4]=[4,5,6,7]>>>numbers[1, 2, 3, 4, 5, 6, 7]
In this example, you replace the7
with a list of values from4
to7
. Note how Python automatically grows the list for you.
You can also insert elements into a list without removing anything. To do this, you can specify a slice of the form[n:n]
at the desired index:
>>>numbers=[1,2,3,7]>>>numbers[3:3]=[4,5,6]>>>numbers[1, 2, 3, 4, 5, 6, 7]
In this example, you insert the desired values at index3
. Because you’re using an empty slice, Python doesn’t replace any of the existing values. Instead, it makes space for the new values as needed.
You can’t do slice assignment ontuple
objects:
>>>numbers[3:3]=[4,5,6]Traceback (most recent call last):...TypeError:'tuple' object does not support item assignment
Because tuples are immutable, they don’t support slice assignment. If you try to do it, then you get aTypeError
exception.
Python lists have several methods that you can use to modify the underlying list. These methods aren’t available for tuples because tuples are immutable, so you can’t change them in place.
In this section, you’ll explore themutator methods available in Pythonlist
objects. These methods are handy in many situations, so they’re great tools for you as a Python developer.
.append(obj)
The.append(obj)
method appends an object to the end of a list as a single item:
>>>a=["a","b"]>>>a.append("c")>>>a['a', 'b', 'c']
In this example, you append the letter"c"
at the end ofa
using the.append()
method, which modifies the list in place.
Note: List mutator methods modify the target listin place. They don’t return a new list:
>>>a=["a","b"]>>>x=a.append("c")>>>print(x)None>>>a['a', 'b', 'c']
In this code, you grab the return value of.append()
inx
. Using theprint()
function, you can uncover that the value isNone
instead of a newlist
object. While this behavior isdeliberate to make it clear that the method mutates the object in place, it can be a common source of confusion when you’re starting to learn Python.
If you use an iterable as an argument to.append()
, then that iterable is added as a single object:
>>>a=["a","b"]>>>a.append(["c","d","e"])>>>a['a', 'b', ['c', 'd', 'e']]
This call to.append()
adds the input list of letters as it is instead of appending three individual letters at the end ofa
. Therefore, the final list has three elements—the two initial strings and one list object. This may not be what you intended if you wanted to grow the list with the contents of the iterable.
.extend(iterable)
The.extend()
method also adds items to the end of a list. However, the argument is expected to be an iterable like another list. The items in the inputiterable
are added as individual values:
>>>a=["a","b"]>>>a.extend(["c","d","e"])>>>a['a', 'b', 'c', 'd', 'e']
The.extend()
method behaves like the concatenation operator (+
). More precisely, since it modifies the list in place, it behaves like the augmented concatenation operator (+=
). Here’s an example:
>>>a=["a","b"]>>>a+=["c","d","e"]>>>a['a', 'b', 'c', 'd', 'e']
The augmented concatenation operator produces the same result as.extend()
, adding individual items at the end of the target list.
.insert(index, obj)
The.insert()
method inserts the input object into the target list at the position specified byindex
. Following the method call,a[<index>]
is<obj>
, and the remaining list elements are pushed to the right:
>>>a=["a","c"]>>>a.insert(1,"b")>>>a['a', 'b', 'c']
In this example, you insert the letter"b"
between"a"
and"c"
using.insert()
. Note that just like.append()
, the.insert()
method inserts the input object as a single element in the target list.
.remove(obj)
The.remove()
method removes the input object from a list. Ifobj
isn’t in the target list, then you get aValueError
exception:
>>>a=["a","b","c","d","e"]>>>a.remove("b")>>>a['a', 'c', 'd', 'e']>>>a.remove("c")>>>a['a', 'd', 'e']
With.remove()
, you can delete specific objects from a given list. Note that this method removes only one instance of the input object. If the object is duplicated, then only its first instance will be deleted.
.pop([index=-1])
The.pop()
method also allows you to remove items from a list. It differs from.remove()
in two aspects:
Calling.pop()
without arguments removes and returns the last item in the list:
>>>a=["a","b","c","d","e"]>>>a.pop()'e'>>>a['a', 'b', 'c', 'd']>>>a.pop()'d'>>>a['a', 'b', 'c']
If you specify the optionalindex
argument, then the item at that index is removed and returned. Note thatindex
can be negative too:
>>>a=["a","b","c","d","e"]>>>a.pop(1)'b'>>>a['a', 'c', 'd', 'e']>>>a.pop(3)'e'>>>a['a', 'c', 'd']>>>a.pop(-2)'c'>>>a['a', 'd']>>>a.pop(-1)'d'>>>a['a']
Theindex
argument defaults to-1
, soa.pop(-1)
is equivalent toa.pop()
.
Several Pythonoperators andbuilt-in functions also work with lists and tuples. For example, thein
andnot in
operators allow you to run membership tests on lists:
>>>words=["foo","bar","baz","qux","quux","corge"]>>>"qux"inwordsTrue>>>"py"inwordsFalse>>>"thud"notinwordsTrue
Thein
operator returnsTrue
if the target object is in the list andFalse
otherwise. Thenot in
operator produces the opposite result.
Theconcatenation (+
) and repetition (*
) operators also work with lists and tuples:
>>>words+["grault","garply"]['foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply']>>>words*2['foo', 'bar', 'baz', 'qux', 'quux', 'corge','foo', 'bar', 'baz', 'qux', 'quux', 'corge']
You can also use the built-inlen()
,min()
,max()
, andsum()
functions with lists and tuples:
>>>numbers=[2,7,5,4,8]>>>len(numbers)5>>>min(numbers)2>>>max(numbers)8>>>sum(numbers)26
In this example, thelen()
function returns the number of values in the list. Themin()
andmax()
functions return the minimum and maximum values in the list, respectively. Thesum()
function returns the sum of the values in the input list.
Finally, it’s important to note that all these functions work the same with tuples. So, instead of using them withlist
objects, you can also usetuple
objects.
A tuple literal can contain several items that you typically assign to a single variable or name:
>>>t=("foo","bar","baz","qux")
When this occurs, it’s as though the items in the tuple have beenpacked into the object, as shown in the diagram below:
If thepacked objects are assigned to a tuple of names, then the individual objects areunpacked as shown in the diagram below, where you use a tuple ofs*
variables:
Here’s how this unpacking works in Python code:
>>>s1,s2,s3,s4=t>>>s1'foo'>>>s2'bar'>>>s3'baz'>>>s4'qux'
Note how each variable receives a single value from the unpacked tuple. When you’re unpacking a tuple, the number of variables on the left must match the number of values in the tuple. Otherwise, you get aValueError
exception:
>>>s1,s2,s3=tTraceback (most recent call last):...ValueError:too many values to unpack (expected 3)>>>s1,s2,s3,s4,s5=tTraceback (most recent call last):...ValueError:not enough values to unpack (expected 5, got 4)
In the first example, the number of variables is less than the items in the tuple, and the error message says that there are too many values to unpack. In the second example, the number of variables exceeds the number of items in the tuple. This time, the error message says that there aren’t enough values to unpack.
You can combine packing and unpacking in one statement to run a parallel assignment:
>>>s1,s2,s3,s4="foo","bar","baz","qux">>>s1'foo'>>>s2'bar'>>>s3'baz'>>>s4'qux'
Again, the number of elements in the tuple on the left of the assignment must equal the number on the right. Otherwise, you get an error.
Tuple assignment allows for a curious bit of idiomatic Python. Sometimes, when programming, you have two variables whose values you need to swap. In most programming languages, it’s necessary to store one of the values in a temporary variable while the swap occurs.
Consider the following example that compares swapping with a temporary variable and unpacking:
>>>a="foo">>>b="bar">>># Using a temporary variable>>>temp=a>>>a=b>>>b=temp>>>a,b('bar', 'foo')>>>a="foo">>>b="bar">>># Using unpacking>>>a,b=b,a>>>a,b('bar', 'foo')
Using a temporary variable to swap values can be annoying, so it’s great that you can do it with a single unpacking operation in Python. This feature also improves your code’s readability, making it more explicit.
Everything you’ve learned so far about lists and tuples can help you decide when to use a list or a tuple in your code. Here’s a summary of when it would be appropriate to use alist instead of a tuple:
Similarly, it’s appropriate to use atuple rather than a list in the following situations:
Finally, tuples can be more memory-efficient than lists, especially for large collections where immutability is acceptable or preferred. Similarly, if the integrity of the data is important and should be preserved throughout the program, tuples ensure and communicate that the data must remain unchanged.
Now you know the basic features of Pythonlists andtuples and understand how to manipulate them in your code. You’ll use these two data types extensively in your Python programming journey.
In this tutorial, you’ve:
With this knowledge, you can now decide when it’s appropriate to use a list or tuple in your Python code. You also have the essential skills to create and manipulate lists and tuples in Python.
Get Your Code:Click here to download the free sample code that shows you how to work with lists and tuples in Python.
Take the Quiz: Test your knowledge with our interactive “Lists vs Tuples in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:
Interactive Quiz
Lists vs Tuples in PythonChallenge yourself with this quiz to evaluate and deepen your understanding of Python lists and tuples. You'll explore key concepts, such as how to create, access, and manipulate these data types, while also learning best practices for using them efficiently in your code.
Now that you have some experience with lists and tuples in Python, you can use the questions and answers below to check your understanding and recap what you’ve learned.
These FAQs are related to the most important concepts you’ve covered in this tutorial. Click theShow/Hide toggle beside each question to reveal the answer.
The key difference between lists and tuples is that lists are mutable, allowing you to modify them after creation, while tuples are immutable so you can’t change them once defined.
You should prefer tuples when you have a fixed collection of items that shouldn’t change, such as coordinates or RGB color values, and when you want to ensure data integrity by preventing modifications.
You can create a list from a tuple by using thelist()
constructor and passing it the tuple as an argument, likelist(my_tuple)
.
Tuples provide a way to group related yet different types of data together while maintaining data integrity by being immutable. They also often use less memory compared to lists.
Yes, tuples are immutable, meaning once you create a tuple, you can’t change, add, or remove its elements.
Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:Lists and Tuples in Python
🐍 Python Tricks 💌
Get a short & sweetPython Trick delivered to your inbox every couple of days. No spam ever. Unsubscribe any time. Curated by the Real Python team.
AboutLeodanis Pozo Ramos
Leodanis is a self-taught Python developer, educator, and technical writer with over 10 years of experience.
» More about LeodanisMasterReal-World Python Skills With Unlimited Access to Real Python
Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:
MasterReal-World Python Skills
With Unlimited Access to Real Python
Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:
What Do You Think?
What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.
Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students.Get tips for asking good questions andget answers to common questions in our support portal.
Keep Learning
Recommended Video Course:Lists and Tuples in Python
Related Tutorials:
Already have an account?Sign-In
Almost there! Complete this form and click the button below to gain instant access:
Lists vs Tuples in Python (Sample Code)