The main difference between tuple and list is mutability. Lists are mutable i.e. the list can be modified whereas a tuple is immutable i.e. tuple cannot be changed after creating.
In the following example, we can see how to override the first element of the list
a = [“apples”, “mangoes”, “oranges”]
a[0] = “berries”
a
The expected output for the above code will be:
>>>a
[“berries”, “mangoes”, “oranges”]
We will get an error stating tuple object does not support the assignment if we try to modify the first element of tuples.
b = (“apples”, “mangoes”, “oranges”)
b[0] = “berries”
b
This is one of the most frequently asked questions in python interviews. You can check out Python interview questions for more such FAQs in python interviews.
You can watch this video on Python for beginners to learn using lists ad tuples in python: