+ 1
What is difference between tuble & list?
6 Antworten
+ 9
List -> Mutable
Tuple -> Immutable
+ 3
A list is an array of same or dissimilar objects(can be a collection of strings, integers etc) and it can be modified in the sense its contents can be deleted or modified as well as new contents can be added as well whereas in a tuple once you declare and define it it's content cannot be modified or deleted and new content cannot be added. Tuple is fixed once it's created.
Tuple-> Immutable
List-> Mutable
Also execution of tuples is faster than lists.
Cheers!!
+ 1
tuple is (1,2,3 ) also you cannot change objects in tuple while list is [1,2 3] and you can change objects In list .. speed for processing tuple is faster than list
+ 1
Here is my primer on tuples in Python - hope you find it useful!
https://code.sololearn.com/cce88fWlK7L7/?ref=app
0
Its also worth noting that tuples are smaller in file size and faster to execute than lists.
if you had these two programs:
lst1 = [1, 2, 3]
print(lst1)
VS:
tple1= (1, 2, 3)
print(tple1)
You'd find the program with the tuple executed faster and had a smaller file size. So its probably good practice to use a tuple in place of a list if you dont need the extra functionality of a list.
0
tuples are inmutables list not, lista are mutables