Tuple vs List: Difference Between List and Tuple in Python
a year ago
Table of Content
Tuple vs List in Python
Difference between List and Tuple in Python with example
In a different article of the same series, we have discussed Lists and Tuples. Both the terms have the same purpose of storing the data with a different nature. Then the question that arises here is what is the difference between list and tuple in python? And why it is necessary to know the difference between list and tuple in python? Lists are used to store dynamic values where Tuples can store static values. In real life, we need to store the data in two ways. In the first way, we store the data in a data structure and later access the data and perform operations on the data. For example, the name of the students. We can store the names in a list and can access the names, insert new names, delete particular names. In a second way, we store the data in a data structure and can access the data only without modifying the data. For example, the name of topper students for a particular year. We can store the topper names in a tuple because once declare, the names will not alter, we can only access the names. So, this is the basic difference between list and tuple in python. In this article, we will take a deeper look at the difference between Lists and Tuples in Python with an example.
Tuple vs List in Python
List and tuples in python are data structures. Both terms in Python are known as a collection of elements where each element is assigned a unique number known as an index. Entries in the Python List/Tuples are known as elements or items. The main difference between List and Tuple in Python is, Python Lists are ordered and mutable. Whereas Python Tuples are ordered and immutable. Once we declare a tuple it cannot be modified or updated. When we talk about Tuple vs List in Python both are the data structures used to store the multiple values under a common name. Lists in Python are dynamic in nature but Tuples are static. Modification of the data inside the list is possible but we cannot modify the data inside the tuple because tuples are immutable. Tuples can be used in a situation where you don’t want to alter the data. This is all about Tuple vs List in Python. Let’s take a deeper look into the difference between List and Tuple in Python.
Difference between List and Tuple in Python with examples
In this article, we discussed Python Tuples vs Lists, the difference between List and Tuple in Python with examples. Python lists are dynamic in nature whereas tuples are static in nature. We can access and modify the elements stored inside the list but we can only access the elements stored in a tuple and cannot modify the elements. We hope you enjoyed the article. If you have any related queries regarding the difference between List and Tuple in Python, feel free to ask in the comment section below.
Liked what you read? Then don’t break the spree. Visit our blog page to read more awesome articles.
Or if you are into videos, then we have an amazing Youtube channel as well. Visit our InsideAIML Youtube Channel to learn all about Artificial Intelligence, Deep Learning, Data Science and Machine Learning.