For working professionals
For fresh graduates
More
Talk to our experts. We are available 7 days a week, 10 AM to 7 PM
Indian Nationals
Foreign Nationals
The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not .
13. Print In Python
15. Python for Loop
19. Break in Python
23. Float in Python
25. List in Python
27. Tuples in Python
29. Set in Python
53. Python Modules
57. Python Packages
59. Class in Python
61. Object in Python
73. JSON Python
79. Python Threading
84. Map in Python
85. Filter in Python
86. Eval in Python
96. Sort in Python
101. Datetime Python
103. 2D Array in Python
104. Abs in Python
105. Advantages of Python
107. Append in Python
110. Assert in Python
113. Bool in Python
115. chr in Python
118. Count in python
119. Counter in Python
121. Datetime in Python
122. Extend in Python
123. F-string in Python
125. Format in Python
131. Index in Python
132. Interface in Python
134. Isalpha in Python
136. Iterator in Python
137. Join in Python
140. Literals in Python
141. Matplotlib
144. Modulus in Python
147. OpenCV Python
149. ord in Python
150. Palindrome in Python
151. Pass in Python
156. Python Arrays
158. Python Frameworks
160. Python IDE
164. Python PIP
165. Python Seaborn
166. Python Slicing
168. Queue in Python
169. Replace in Python
173. Stack in Python
174. scikit-learn
175. Selenium with Python
176. Self in Python
177. Sleep in Python
179. Split in Python
184. Strip in Python
185. Subprocess in Python
186. Substring in Python
195. What is Pygame
197. XOR in Python
198. Yield in Python
199. Zip in Python
In Python, List and Tuples are built-in data structures for storing and managing the collections of data. A list is like a flexible notebook where you can add, remove, or rearrange items. On the other hand, a tuple is like a sealed envelope — once packed, its contents remain unchanged. While they might look similar, the differences between list and tuple are really important for how you’ll use them in your programs.
It can be a bit tricky to know when to use a list or a tuple. Many developers find themselves mixing them up, which can lead to slower code, unexpected bugs, or even wasted resources. This confusion usually stems from not fully knowing their unique features and the best scenarios to use them in.
But don’t worry! It’s actually pretty easy to sort this out. By learning about key distinctions like mutability, performance, and use cases, you'll be able to confidently decide when to use each one.
In this article, we will explore what is list, what is tuple and the key difference between tuple and list in Python with the help of examples. Whether you’re just starting with Python or looking to sharpen your skills, this guide will help you write smarter and more efficient code. Happy coding!
“Enhance your Python skills further with our Data Science and Machine Learning courses from top universities — take the next step in your learning journey!”
A list in Python is a built-in data structure that enables you to store a collection of items. These items can vary in data types, including integers, strings, or even other lists.
Lists are among the most versatile and frequently used data structures in Python because they are mutable, which means you can modify their contents after they've been created.
list_name = [element1, element2, element3, ...]
Also Read: Lists Methods in Python
A tuple in Python is an ordered and immutable collection of elements. It is similar to a list, but unlike lists, tuples cannot be modified after they are created.
Tuples are defined using parentheses () and can hold elements of various data types, including integers, strings, floats, and even other collections.
tuple_name = (element1, element2, element3, ...)
“Start your coding journey with our complimentary Python courses designed just for you — dive into Python programming fundamentals, explore key Python libraries, and engage with practical case studies!”
Parameter | List | Tuple |
Definition | A list is an ordered, mutable collection of items. | A tuple is an ordered, immutable collection of items. |
Syntax | Defined using square brackets [ ]. | Defined using parentheses ( ) . |
Mutability | Mutable: Elements can be added, removed, or modified. | Immutable: Elements cannot be changed once the tuple is created. |
Performance | Slower due to dynamic resizing and mutability. | Faster due to immutability and smaller memory footprint. |
Memory Usage | Consumes more memory as it supports additional functionalities like append or pop. | Consumes less memory as it has fewer functionalities. |
Methods Available | Provides methods like append(), remove(), sort(), etc. | Limited methods like count() and index(). |
Use Case | Suitable for dynamic collections where data changes frequently. | Ideal for fixed data that does not require modification. |
Iteration Speed | Slower than tuples during iteration. | Faster due to immutability and reduced overhead. |
Error Safety | More prone to accidental changes or bugs. | Safer as the data remains constant throughout the program. |
Nesting Capability | Can nest lists, tuples, or other collections. | Can also nest tuples or other collections. |
Type Conversion | A list can be converted to a tuple using tuple(). | A tuple can be converted to a list using list(). |
Let’s create an employee dataset, and then perform different operations of list on that.
# Dataset of employee details with Indian names
employee_data = [
{"Name": "Aditi", "Department": "HR"},
{"Name": "Rahul", "Department": "IT"},
{"Name": "Sneha", "Department": "Finance"}
]
# Extracting employee names into a list
employee_names = [employee["Name"] for employee in employee_data]
# Printing the list of names
print("List of Employee Names:", employee_names)
Output
List of Employee Names: ['Aditi', 'Rahul', 'Sneha']
Now, let’s perform different Python list operations
# List of employee names (extracted from the dataset)
employee_names = ['Aditi', 'Rahul', 'Sneha']
# Accessing elements in the list
print("First Employee:", employee_names[0]) # Access the first element
print("Last Employee:", employee_names[-1]) # Access the last element
# Adding a new employee to the list
employee_names.append('Ankit')
print("Updated List of Employees:", employee_names)
# Removing an employee from the list
employee_names.remove('Rahul')
print("After Removing Rahul:", employee_names)
# Iterating through the list
print("Employee Names:")
for name in employee_names:
print(name)
# Checking if an employee exists in the list
if 'Sneha' in employee_names:
print("Sneha is in the list.")
else:
print("Sneha is not in the list.")
Output
First Employee: Aditi
Last Employee: Sneha
Updated List of Employees: ['Aditi', 'Rahul', 'Sneha', 'Ankit']
After Removing Rahul: ['Aditi', 'Sneha', 'Ankit']
Employee Names:
Aditi
Sneha
Ankit
Sneha is in the list.
Here, we will do same. First we will create a dataset and then perform operations on tuple.
# Tuple of city weather data
weather_data = (
("Mumbai", 32, 75),
("Delhi", 38, 50),
("Chennai", 34, 80),
("Kolkata", 30, 85),
)
# Access weather data for Mumbai
mumbai_weather = weather_data[0]
print("Weather data for Mumbai:", mumbai_weather)
# Display weather data for all cities
for city, temperature, humidity in weather_data:
print(f"City: {city}, Temperature: {temperature}°C, Humidity: {humidity}%")
# Find the city with the highest temperature
hottest_city = max(weather_data, key=lambda x: x[1])
print("Hottest city:", hottest_city[0])
# Convert the tuple to a list to add new city data
weather_data_list = list(weather_data)
weather_data_list.append(("Bengaluru", 28, 70))
weather_data = tuple(weather_data_list) # Convert back to a tuple
print("Updated weather data:", weather_data)
Output
Weather data for Mumbai: ('Mumbai', 32, 75)
City: Mumbai, Temperature: 32°C, Humidity: 75%
City: Delhi, Temperature: 38°C, Humidity: 50%
City: Chennai, Temperature: 34°C, Humidity: 80%
City: Kolkata, Temperature: 30°C, Humidity: 85%
Hottest city: Delhi
Updated weather data: (('Mumbai', 32, 75), ('Delhi', 38, 50), ('Chennai', 34, 80), ('Kolkata', 30, 85), ('Bengaluru', 28, 70))
With upGrad, you can access global standard education facilities right here in India. upGrad also offers free Python courses that come with certificates, making them an excellent opportunity if you're interested in data science and machine learning.
By enrolling in upGrad's Python courses, you can benefit from the knowledge and expertise of some of the best educators from around the world. These instructors understand the diverse challenges that Python programmers face and can provide guidance to help you navigate them effectively.
So, reach out to an upGrad counselor today to learn more about how you can benefit from a Python course.
Here are some of the best data science and machine learning courses offered by upGrad, designed to meet your learning needs:
Similar Reads: Top Trending Blogs of Python
Mutability: Lists are mutable, which means their elements can be changed after creation. Tuples are immutable; once defined, their elements cannot be altered.Syntax: Lists are defined using square brackets [], while tuples use parentheses ().Performance: Due to their immutability, tuples can be more memory-efficient and faster than lists, especially when iterating over large sequences.Use Cases: Lists are suitable for collections of items that may change during program execution, such as elements that need to be added, removed, or modified. Tuples are ideal for fixed collections of items, like coordinates or other data that should remain constant. Mutability: Lists are mutable, which means their elements can be changed after creation. Tuples are immutable; once defined, their elements cannot be altered. Mutability : Lists are mutable, which means their elements can be changed after creation. Tuples are immutable; once defined, their elements cannot be altered. Syntax: Lists are defined using square brackets [], while tuples use parentheses (). Syntax : Lists are defined using square brackets [], while tuples use parentheses (). Performance: Due to their immutability, tuples can be more memory-efficient and faster than lists, especially when iterating over large sequences. Performance : Due to their immutability, tuples can be more memory-efficient and faster than lists, especially when iterating over large sequences. Use Cases: Lists are suitable for collections of items that may change during program execution, such as elements that need to be added, removed, or modified. Tuples are ideal for fixed collections of items, like coordinates or other data that should remain constant. Use Cases : Lists are suitable for collections of items that may change during program execution, such as elements that need to be added, removed, or modified. Tuples are ideal for fixed collections of items, like coordinates or other data that should remain constant.
The choice between a list and a tuple depends on your program's specific needs: Use a list when: You need a mutable sequence that allows modifications, such as adding, removing, or changing elements.Use a tuple when: You require an immutable sequence to ensure that the data remains constant throughout the program. Use a list when: You need a mutable sequence that allows modifications, such as adding, removing, or changing elements. Use a list when : You need a mutable sequence that allows modifications, such as adding, removing, or changing elements. Use a tuple when: You require an immutable sequence to ensure that the data remains constant throughout the program. Use a tuple when : You require an immutable sequence to ensure that the data remains constant throughout the program.
Tuples are designed to be immutable to provide data integrity and allow for optimizations: Data Integrity: Immutability ensures that the data cannot be altered accidentally, which is crucial for fixed collections of items.Performance: Immutability allows Python to make internal optimizations, leading to potential performance improvements in terms of speed and memory usage. Data Integrity: Immutability ensures that the data cannot be altered accidentally, which is crucial for fixed collections of items. Data Integrity : Immutability ensures that the data cannot be altered accidentally, which is crucial for fixed collections of items. Performance: Immutability allows Python to make internal optimizations, leading to potential performance improvements in terms of speed and memory usage. Performance : Immutability allows Python to make internal optimizations, leading to potential performance improvements in terms of speed and memory usage.
Yes, tuples can contain duplicate elements.
Yes, you can concatenate two tuples using the + operator.
remove() method: Removes the first occurrence of a specified value from the list.del statement: Deletes an item at a specific index or slices the list to remove multiple items. remove() method: Removes the first occurrence of a specified value from the list. remove() method : Removes the first occurrence of a specified value from the list. del statement: Deletes an item at a specific index or slices the list to remove multiple items. del statement : Deletes an item at a specific index or slices the list to remove multiple items.
You can convert a list to a tuple using the tuple() constructor.
Generally, tuples can be slightly faster than lists due to their immutability, which allows for optimizations. However, the performance difference is usually minimal and should not be the sole factor in choosing between them.
Tuples can be created by placing comma-separated values within parentheses
Mutable Objects: Objects whose state or content can be changed after creation. Examples include lists, dictionaries, and sets.Immutable Objects: Objects whose state or content cannot be changed once created. Examples include tuples, strings, and integers. Mutable Objects: Objects whose state or content can be changed after creation. Examples include lists, dictionaries, and sets. Mutable Objects : Objects whose state or content can be changed after creation. Examples include lists, dictionaries, and sets. Immutable Objects: Objects whose state or content cannot be changed once created. Examples include tuples, strings, and integers. Immutable Objects : Objects whose state or content cannot be changed once created. Examples include tuples, strings, and integers.
-9cd0a42cab014b9e8d6d4c4ba3f27ab1.webp&w=3840&q=75)
Take our Free Quiz on Python
Answer quick questions and assess your Python knowledge
FREE COURSES
Start Learning For Free

Author|907 articles published
Recommended Programs