Difference between list and tuple in Python

Introduction

So you are curious to know the key difference between a list and tuple in Python ? You can find the answer in many places on the web, however in this code snippet we will summarize it so that it is easy to remember. Take a look at the following table…

List vs Tuple in Python

Here are the main differences…

Python ListPython Tuple
Collection data typeCollection data type
Mutable (i.e. can be modified)
Immutable (i.e. cannot be modified)
Use square brackets [] to define
Use parenthesis () to define
Can hold data of different typesCan hold data of different types
Elements are orderedElements are ordered
Mainly used to collect similar Items (can be tuples)Mainly used to group data as one item
Similar to arrays in other languagesSimilar to records or struct in other languages

Code

Let us now demonstrate the concepts mentioned in the table above…

If we run the code snippet code above, we should get the following output:

That is all for today. Thanks for visiting.

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *