x = [23, 9, 7, 9]
x[23, 9, 7, 9]
x = [23, 9, 7, 9]
x[23, 9, 7, 9]
type(x)list
append(): add item to end of listx.append(12)
x[23, 9, 7, 9, 12]
extend(): Append elements of another iterablez = [19, 21]
x.extend(z)
x[23, 9, 7, 9, 12, 19, 21]
pop(): Remove and return element of list by indexDefaults to the last element
x[23, 9, 7, 9, 12, 19, 21]
x.pop()21
x[23, 9, 7, 9, 12, 19]
Remove and return the 5th element:
x.pop(4)12
insert(): Insert element before indexNote the function requires two inputs, there is no default location to insert
x.insert(4, 13)x[23, 9, 7, 9, 13, 19]
remove(): remove first occurence of valuex
x.remove(13)
x[23, 9, 7, 9, 19]
count(): Count occurences of a value in the listx.count(9)2
copy(): make a (shallow) copy of the listz = x.copy()
z[23, 9, 7, 9, 19]
reverse(): Reverse elements in-placex.reverse()sort(): sort list in-placeDefaults to ascending order
x.sort()
x[7, 9, 9, 19, 23]
reverse:x.sort(reverse=True)
x[23, 19, 9, 9, 7]
clear(): remove all list itemsx.clear()
x[]
x = [[1, 3, 5], [21, 25, 29]]
x[[1, 3, 5], [21, 25, 29]]
len(x)2
* and +["A", "B"] * 3['A', 'B', 'A', 'B', 'A', 'B']
[21, 22] + [31, 32][21, 22, 31, 32]
[1, 2] * 2 + [3, 4] * 3[1, 2, 1, 2, 3, 4, 3, 4, 3, 4]