+ 1

Python.

What is the difference in list and tuples in python?

11th Jul 2025, 4:43 AM
Tanvi Saxena
Tanvi Saxena - avatar
4 Respuestas
+ 3
Tanvi Saxena , besides of what Afnan Irtesum Chowdhury mentioned, tuples are slightly faster in searching and lookup. this is due to how tuples and lists are stored in memory. > tuples uses a continuous memory block. > lists store pointers to list objects.
11th Jul 2025, 10:25 AM
Lothar
Lothar - avatar
+ 3
Lists are mutable(items can be changed after a list has been created). Tuples are immutable(items can NOT be changed after a tuple has been created). Example: # list my_list = ["Python", "C", "Java"] my_list[1] = "C++" # valid # tuple my_tuple = ("Python", "C", "Java") my_tuple[2] = "Kotlin" # TypeError: "tuple" object does not support item assignment
11th Jul 2025, 5:18 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
+ 1
if you're not going to modify it, use tuples. otherwise, use list.
12th Jul 2025, 2:30 AM
Bob_Li
Bob_Li - avatar
0
Hi
11th Jul 2025, 10:52 PM
abd elhafid zahiri