Skip to content
techsnow

Data Structures

List Methods

MethodWhat it does
append(x)Add x to the end
insert(i, x)Insert x at position i
extend(list)Add every item of another list
remove(x)Remove the first x
pop() / pop(i)Remove and return the last item / item i
index(x)Position of x
count(x)How many times x appears
sort()Sort in place
reverse()Reverse in place
copy()A shallow copy
marks = [72, 85, 64]
marks.append(91)
marks.sort()
print(marks)                 # [64, 72, 85, 91]
print(sorted(marks, reverse=True))  # [91, 85, 72, 64]
print(sum(marks) / len(marks))      # 78.0