= [23, 9, 7, 9]
x x
[23, 9, 7, 9]
= [23, 9, 7, 9]
x x
[23, 9, 7, 9]
type(x)
list
append()
: add item to end of list12)
x.append( x
[23, 9, 7, 9, 12]
extend()
: Append elements of another iterable= [19, 21]
z
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:
4) x.pop(
12
insert()
: Insert element before indexNote the function requires two inputs, there is no default location to insert
4, 13) x.insert(
x
[23, 9, 7, 9, 13, 19]
remove()
: remove first occurence of value
x13)
x.remove( x
[23, 9, 7, 9, 19]
count()
: Count occurences of a value in the list9) x.count(
2
copy()
: make a (shallow) copy of the list= x.copy()
z z
[23, 9, 7, 9, 19]
reverse()
: Reverse elements in-place x.reverse()
sort()
: sort list in-placeDefaults to ascending order
x.sort() x
[7, 9, 9, 19, 23]
reverse
:=True)
x.sort(reverse x
[23, 19, 9, 9, 7]
clear()
: remove all list items
x.clear() x
[]
= [[1, 3, 5], [21, 25, 29]]
x 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]