Difference Between Set vs List vs Tuple

The utilization of data structures in Python presents a perplexing and convoluted method of depicting numbers, strings, and other Python objects in a collection of values. Python's built-in data structures, such as lists, tuples, and sets, are captivating and exhibit distinctive traits that differentiate them from one another. These data structures possess an extraordinary capacity to hold groups of objects, rendering them one of a kind. In this article, we will see which among the three fits best with examples.


Items can be changed, added to, or taken out of after they are made. It can also be altered and arranged in any order, and because it is categorized, individual items can be accessed based on where they are.


my_list = [1, 2, 3, 4, 5]


[1, 2, 3, 4, 5]

A collection of items that can be changed and arranged is what you get when you make a list. The items can be enclosed within square brackets and the list() function used to create it. Indexing or slicing are used to access elements; the append() and extend() methods are used to add elements; the remove() and pop() methods are used to remove elements; the in keyword is used to check for elements; the len() function is used to determine the length of a list; and the sort() method is used to sort and reverse the order of the elements in the list.


# Create a list
fruits = ['apple', 'banana', 'orange']

# Access elements

# Add elements

# Remove elements

# Check if element is in list
print('apple' in fruits)

# Find length of list

# Sort the list

# Reverse the list


['apple', 'banana', 'orange', 'kiwi']
['apple', 'orange', 'kiwi']
['apple', 'kiwi', 'orange']
['orange', 'kiwi', 'apple']


a collection of things that cannot be changed, are ordered, and cannot be added to after they have been created; Also, you can't change anything about it); and indexable (you can locate a particular item by its location).


my_tuple = (1, 2, 3, 4, 5)


(1, 2, 3, 4, 5)

One of two methods can be used to create them: either by using the tuple() function or by bracketing the components. Ordering or slicing are used to get at the parts of a tuple. Because they are permanent, no components can be changed after they are created. You can use the word "in'' to determine whether a tuple contains an ingredient. Utilize the len() function to determine a tuple's extent. Dates and locations, for example, are commonly stored in triples because they cannot be altered after they are formed.


Unsorted gathering of distinct things that cannot contain duplicates; in addition, since sets are not indexed, individual items cannot be found based on their location.


my_set = {1, 2, 3, 4, 5}


{1, 2, 3, 4, 5}

A comma-separated list of values enclosed in curly braces can be used to make a set in Python, which is an unordered collection of distinct components. The add() technique or update() method can be used to add items to a set. While the discard() method does nothing when removing components, the delete() method will generate an error. You can execute set procedures like union, intersection, and difference, and you can turn a list into a set using the set() function. When eliminating copies from a list or applying set procedures to it, this is helpful.


# Create a set
numbers = {1, 2, 3, 4}

# Add elements

# Remove elements

# Check if element is in set
print(2 in numbers)

# Find length of set

# Perform set operations
set1 = {1, 2, 3}
set2 = {2, 3, 4}

# Convert list to set
numbers_list = [1, 2, 3, 4, 5]
numbers_set = set(numbers_list)


{1, 2, 3, 4, 5}
{1, 2, 4, 5}
{1, 2, 3, 4}
{2, 3}

List vs. Tuple vs. Set - Comparison

After learning about the basics of list, tuple, and set data structures, let's compare them in terms of different aspects.

Mutable vs Immutable

Tuples are immutable, so when they are described, their component components cannot be altered. You can add, delete, or modify the components in records and sets because they are changeable. Use a tuple if you require a data format that cannot be modified; otherwise, use a set or list.


Lists and tuples maintain the order of elements, whereas sets do not. Sets are unordered, and elements are arranged randomly.

Duplicate Elements

Lists and sets allow duplicate elements, whereas tuples do not. Sets have a unique property that they only store unique elements. Therefore, if you want to store only unique values, use a set, otherwise use a list or a tuple.


Due to the internal implementation of these data structures, sets are faster for membership checking and de-duplication, whereas lists and tuples are slower for indexing.


  • Python's most common data format is lists. They are useful for showing numbers in a rundown, like sections in a data set or lines in a record.

  • The elements of a vector and the coordinates of a point are two examples of fixed groups of linked values that are able to be expressed using tuples.

  • Sets are useful when you need to hold a variety of novel characteristics or perform specific tasks like association, convergence, and distinction.


We talked about the Python differences between lists, tuples, and sets in this tutorial. Records and sets are variable, meaning you can add, eliminate or alter the components in them, though tuples are unchanging, meaning you can't add, eliminate or adjust the components in them whenever they are characterized. Sets do not keep the order of the elements, but lists and tuples do. Lists and tuples can contain duplicate elements, whereas sets only allow for unique elements. Last but not least, indexing and membership checking take longer with sets than with lists and tuples. Contingent upon your requirements, you can pick the proper information design to make your code more successful and adaptable.

Updated on: 18-Apr-2023


Kickstart Your Career

Get certified by completing the course

Get Started