|
| Home |
|---|
In Python programming, tuples and lists are both used to store collections of values. However, tuples are immutable, which means their values cannot be changed after creation.
Sometimes we need to convert a tuple into a list so that we can
modify the values. Python allows this conversion easily using
the list() function.
numbers = (10,20,30,40)
print(numbers)
(10, 20, 30, 40)
The most common way to convert a tuple into a list is by using
the built-in list() function.
numbers = (10,20,30,40)
numbers_list = list(numbers)
print(numbers_list)
[10, 20, 30, 40]
After converting the tuple to a list, the elements can be modified.
numbers = (10,20,30)
numbers_list = list(numbers)
numbers_list.append(40)
print(numbers_list)
[10, 20, 30, 40]
Tuples containing text values can also be converted into lists.
fruits = ("apple","banana","mango")
fruit_list = list(fruits)
print(fruit_list)
['apple', 'banana', 'mango']
A common use of this conversion is modifying tuple values.
colors = ("red","green","blue")
color_list = list(colors)
color_list[1] = "yellow"
print(color_list)
['red', 'yellow', 'blue']
| Tuple | List |
|---|---|
| Immutable (cannot change values) | Mutable (values can be changed) |
| Uses parentheses () | Uses square brackets [] |
| Generally faster | More flexible |
Converting a tuple to a list allows Python programmers to modify data that was originally stored in an immutable tuple.
The list() function is the simplest way to perform
this conversion.
Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.
Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.
Home Tutorial Online Live Trainings Contact Us © 2026 All rights reserved by www.PythonTutor.net