-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_tuple.py
More file actions
32 lines (26 loc) · 766 Bytes
/
list_tuple.py
File metadata and controls
32 lines (26 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# List vs Tuple
# https://www.afternerd.com/blog/difference-between-list-tuple/
# The main difference between lists and a tuples is the fact that lists are
# mutable whereas tuples are immutable.
# Appending performance: Mutability Wins!
# Easiness of debugging: Immutability Wins!
# Memory efficiency: Immutability Wins !
# list -> mutable
print "---list---"
a = ["akash", "test"]
print "a: {}".format(a)
# tuple -> immutable
print "---tuple---"
b = ("akash", "test")
print "b: {}".format(b)
# modify
print "updating list"
a[0] = 'sky'
print "a: {}".format(a)
print "updating tuple"
try:
b[0] = 'sky'
except Exception as e:
print "exception: {}".format(e)
# ERROR TypeError: 'tuple' object does not support item assignment
print "b: {}".format(b)