FresherFresher (0–1 yrs)CodingPythonTCSInfosysAmazon
List vs Tuple
Difference between list and tuple in Python? When do you use each?
Answers use simple, clear English.
Quick interview answer
Lists are mutable and typically used for homogeneous growing collections. Tuples are immutable, hashable (if elements are), and good for fixed records, dictionary keys, and safer APIs. Prefer tuples for return packs of fixed shape.
Detailed answer
Lists are mutable and typically used for homogeneous growing collections. Tuples are immutable, hashable (if elements are), and good for fixed records, dictionary keys, and safer APIs. Prefer tuples for return packs of fixed shape.
Code example
coords = (10, 20) # tuple
nums = [1, 2, 3] # list
nums.append(4)Practice code · python (view only · no execution)
coords = (10, 20) # tuple
nums = [1, 2, 3] # list
nums.append(4)#basics#oop