What's the difference between lists and tuples?

Lists and tuples are both used to store multiple items in a single variable, but they are different in a few key ways.

A list is defined using square brackets [] and items in a list are separated by commas. Lists are mutable, which means their elements can be modified after they are created.

Watch a course Python - The Practical Guide

A tuple is defined using parentheses () and items in a tuple are separated by commas. Tuples are immutable, which means their elements cannot be modified after they are created.

Here is an example of a list and a tuple:

# list example
fruits = ['apple', 'banana', 'orange']
fruits.append('mango')
print(fruits)

# Output: ['apple', 'banana', 'orange', 'mango']

# tuple example
fruits = ('apple', 'banana', 'orange')
# fruits.append('mango')  # this will give an error
print(fruits)

# Output: ('apple', 'banana', 'orange')

As you can see in the above example, we were able to add an element "mango" to the list but not in tuple.