Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 2 of 10 · Python Basics & Syntax
Interview question

What is the difference between a list and a tuple in Python? Python में list और tuple में क्या अंतर है?

Answer
AspectListTuple
MutabilityMutable - can change after creationImmutable - cannot change
Syntax[1, 2, 3](1, 2, 3)
PerformanceSlightly slowerFaster, less memory overhead
Use caseData that changes (dynamic collections)Fixed data, dictionary keys
my_list = [1, 2, 3]
my_list.append(4)  # works fine
my_list[0] = 99     # works fine

my_tuple = (1, 2, 3)
# my_tuple.append(4)  # AttributeError
# my_tuple[0] = 99     # TypeError

# Tuples can be dict keys, lists cannot
locations = {(28.7, 77.1): 'Delhi'}  # works
# {[28.7, 77.1]: 'Delhi'}  # TypeError - unhashable
पहलूListTuple
MutabilityMutableImmutable
Syntax[1, 2, 3](1, 2, 3)
Performanceथोड़ा धीमातेज़, कम memory
Use caseबदलने वाला dataFixed data, dict keys
my_list = [1, 2, 3]
my_list.append(4)
my_list[0] = 99

my_tuple = (1, 2, 3)
# my_tuple.append(4)  # AttributeError
# my_tuple[0] = 99     # TypeError

Was this answer clear?