Python में List और Tuple में अंतर (Table + Examples)
List mutable है, tuple immutable — लेकिन interviewers 6 और अंतर expect करते हैं. Memory और speed proof के साथ पूरी comparison table.
The one-line answer
[ ], tuple uses ( ). But interviews expect more — here are all 7 differences.my_list = [10, 20, 30] # list - square brackets
my_tuple = (10, 20, 30) # tuple - round brackets
my_list[0] = 99 # OK: list changed
my_tuple[0] = 99 # TypeError: 'tuple' object does not
# support item assignment
Full comparison table (7 differences)
| Point | List | Tuple |
|---|---|---|
| Mutability | Mutable — add/remove/change | Immutable — locked forever |
| Syntax | [1, 2, 3] | (1, 2, 3) |
| Methods | 11+ (append, remove, sort...) | Only 2 (count, index) |
| Speed | Slower | Faster (fixed size) |
| Memory | More (extra space for growth) | Less (exact fit) |
| Dictionary key | ❌ Cannot be a dict key | ✅ Can be a dict key |
| Use case | Data that changes (cart items) | Fixed data (coordinates, dates) |
Memory proof (run this yourself)
import sys
l = [10, 20, 30, 40, 50]
t = (10, 20, 30, 40, 50)
print("List size :", sys.getsizeof(l), "bytes")
print("Tuple size:", sys.getsizeof(t), "bytes")
Same 5 items, tuple takes less memory — because a list reserves extra space for future growth, a tuple never grows.
The dictionary-key difference (interview favourite)
locations = { (28.61, 77.20): "Delhi" } # tuple key: OK
print(locations[(28.61, 77.20)])
wrong = { [28.61, 77.20]: "Delhi" } # TypeError:
# unhashable type: 'list'
Only immutable objects can be dictionary keys. Since a tuple cannot change, Python can hash it; a list can change, so it cannot be hashed.
When to use which?
- Use a list when data will change: shopping cart, student attendance, todo items.
- Use a tuple when data must never change: (latitude, longitude), RGB colours, date of birth, function returning multiple values.
- Interview line: "Tuple is a read-only list — safer, faster and hashable."
One-line answer
[ ] use करती है, tuple ( ). लेकिन interviews में और expect किया जाता है — यहां सभी 7 अंतर हैं.my_list = [10, 20, 30] # list - square brackets
my_tuple = (10, 20, 30) # tuple - round brackets
my_list[0] = 99 # OK: list बदल गई
my_tuple[0] = 99 # TypeError: 'tuple' object does not
# support item assignment
पूरी comparison table (7 अंतर)
| Point | List | Tuple |
|---|---|---|
| Mutability | Mutable — add/remove/change | Immutable — हमेशा के लिए locked |
| Syntax | [1, 2, 3] | (1, 2, 3) |
| Methods | 11+ (append, remove, sort...) | सिर्फ 2 (count, index) |
| Speed | धीमी | तेज़ (fixed size) |
| Memory | ज़्यादा (growth के लिए extra space) | कम (exact fit) |
| Dictionary key | ❌ dict key नहीं बन सकती | ✅ dict key बन सकता है |
| Use case | बदलने वाला data (cart items) | Fixed data (coordinates, dates) |
Memory proof (खुद run करके देखें)
import sys
l = [10, 20, 30, 40, 50]
t = (10, 20, 30, 40, 50)
print("List size :", sys.getsizeof(l), "bytes")
print("Tuple size:", sys.getsizeof(t), "bytes")
Same 5 items, tuple कम memory लेता है — क्योंकि list future growth के लिए extra space reserve करती है, tuple कभी grow नहीं होता.
Dictionary-key वाला अंतर (interview favourite)
locations = { (28.61, 77.20): "Delhi" } # tuple key: OK
print(locations[(28.61, 77.20)])
wrong = { [28.61, 77.20]: "Delhi" } # TypeError:
# unhashable type: 'list'
सिर्फ immutable objects dictionary keys बन सकते हैं. Tuple बदल नहीं सकता, इसलिए Python उसे hash कर सकता है; list बदल सकती है, इसलिए hash नहीं हो सकती.
कब कौन-सा use करें?
- List use करें जब data बदलेगा: shopping cart, student attendance, todo items.
- Tuple use करें जब data कभी नहीं बदलना चाहिए: (latitude, longitude), RGB colours, date of birth, function से multiple values return.
- Interview line: "Tuple एक read-only list है — safer, faster और hashable."
Frequently Asked Questions
List और tuple में main अंतर क्या है?
List mutable है — बनने के बाद items add, remove या change हो सकते हैं — जबकि tuple immutable है और एक बार बनने के बाद modify नहीं हो सकता.
Tuple list से तेज़ क्यों है?
Tuple का size fixed होता है, इसलिए Python एक बार exact memory allocate करके internal optimizations लगाता है, जबकि list growth के लिए extra space और bookkeeping रखती है.
क्या tuple dictionary key बन सकता है?
हां, क्योंकि tuples immutable हैं इसलिए hashable हैं. Lists dictionary keys नहीं बन सकतीं क्योंकि वे बदल सकती हैं.