Compound Datatypes¶
Compound Datatypes By Example: List, Tuple¶
Typical “sequence” types …
l = [1,2,3]
l.append(4)
l.extend([5,6,7])
l += [8,9]
new_l = l + [10,11]
|
|
t = (1,2,3)
t = (1,)
new_t = t + (4,5)
|
|
Compound Datatypes By Example: Dictionary¶
>>> d = {1:'one', 2:'two'}
>>> d[2]
'two'
>>> d[3] = 'three'
>>> 3 in d
True
>>> del d[3]
>>> 3 in d
False
|
|
Compound Datatypes By Example: Set¶
>>> s = {1,2,3}
>>> 1 in s
True
>>> s.add(4)
>>> s
{1, 2, 3, 4}
>>> s.remove(1)
>>> 1 in s
False
|
|