Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 1 of 10 · Data Types and Data Structures
Interview question

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

Answer
FeatureListTuple
Syntax[1, 2, 3](1, 2, 3)
MutabilityMutableImmutable
SpeedSlowerFaster
MemoryMoreLess
Dict KeyNoYes
my_list = [1, 2, 3]
my_list[0] = 99  # Works - mutable

my_tuple = (1, 2, 3)
my_tuple[0] = 99  # TypeError - immutable

# Tuples as dict keys
my_dict = {(1, 2): 'value'}  # Works
my_dict[[1, 2]] = 'value'  # TypeError
FeatureListTuple
Syntax[1, 2, 3](1, 2, 3)
MutabilityMutableImmutable

Was this answer clear?