List
list = ['apple', 'banana', 'candy']
print(list[0])
print(list[-1])
print(len(list))
list.append('watermelon')
list.insert(0, 'fruits')
list.pop()
list.pop(1)
Tuple
single_el_tuple = (1,)
multiple_el_tuple = (1, 2)
Set
s1 = set([1, 2, 3, 2, 1]) # {1, 2, 3}
s2 = set([2, 3, 4, 5]) # {2, 3, 4, 5}
# add
s1.add(6)
# del
s1.remove(6)
# union
s1 | s2
# intersection
s1 & s2
# difference
s1 - s2
s2 - s1
Dict
dict = {
'key': 'value'
}
# existence
'key' in dict
# add
dict['new_key'] = 'new value'
# get
dict['key']
dict.get('key')
dict.get('not_exist', 'default_value')
# del
dict.pop('key')