Difference between List VS Set VS Tuple in Python - GeeksforGeeks

08 Jun, 2021
List: Lists are just like dynamic sized arrays, declared in other languages (vector in C++ and ArrayList in Java). Lists need not be homogeneous always which makes it the most powerful tool in Python. The main characteristics of lists are – 
The list is a datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.
List are mutable .i.e it can be converted into another data type and can store any data element in it.
List can store any type of element.
Example:
Python3
# Python3 program to demonstrate # List    # Creating a ListList = []print("Blank List: ")print(List)   # Creating a List of numbersList = [10, 20, 14]print("\nList of numbers: ")print(List)   # Creating a List of strings and accessing# using indexList = ["Geeks", "For", "Geeks"]print("\nList Items: ")print(List[0]) print(List[2])
Output:
Blank List: 
[]

List of numbers: 
[10, 20, 14]

List Items: 
Geeks
Geeks
Tuple: Tuple is a collection of Python objects much like a list. The sequence of values stored in a tuple can be of any type, and they are indexed by integers. Values of a tuple are syntactically separated by ‘commas’. Although it is not necessary, it is more common to define a tuple by closing the sequence of values in parentheses. The main characteristics of tuples are – 
Tuple is an immutable sequence in python.
It cannot be changed or replaced since it is immutable.
It is defined under parenthesis().
Tuples can store any type of element.
Example:
Python3
# Creating an empty TupleTuple1 = ()print("Initial empty Tuple: ")print (Tuple1)   # Creating a Tuple with# the use of listlist1 = [1, 2, 4, 5, 6]print("\nTuple using List: ")print(tuple(list1))   #Creating a Tuple #with the use of built-in functionTuple1 = tuple('Geeks')print("\nTuple with the use of function: ")print(Tuple1)
Output:
Initial empty Tuple: 
()

Tuple using List: 
(1, 2, 4, 5, 6)

Tuple with the use of function: 
('G', 'e', 'e', 'k', 's')
Set: In Python, Set is an unordered collection of data type that is iterable, mutable, and has no duplicate elements. The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set. The main characteristics of set are –
Sets are an unordered collection of elements or unintended collection of items In python.
Here the order in which the elements are added into the set is not fixed, it can change frequently.
It is defined under curly braces{}
Sets are mutable, however, only immutable objects can be stored in it.
Example:
Python3
# Python3 program to demonstrate # Set in Python   # Creating a Setset1 = set()print("Initial blank Set: ")print(set1)   # Creating a Set with# the use of Constructor# (Using object to Store String)String = 'GeeksForGeeks'set1 = set(String)print("\nSet with the use of an Object: " )print(set1)   # Creating a Set with# the use of a Listset1 = set(["Geeks", "For", "Geeks"])print("\nSet with the use of List: ")print(set1)
Output:
Initial blank Set: 
set()

Set with the use of an Object: 
{'G', 's', 'e', 'o', 'r', 'F', 'k'}

Set with the use of List: 
{'Geeks', 'For'}
ritikchanna
sweetyty
python-list
python-set
python-tuple
Difference Between
Python
python-list
python-set
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Difference between Process and Thread
Difference Between Method Overloading and Method Overriding in Java
Stack vs Heap Memory Allocation
Differences between JDK, JRE and JVM
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe
Taking input in Python