Skip to content
Justice Tech School

List Methods

append, extend, insert, remove, pop, index, count, sort and reverse change lists in place. sorted() returns a new list.

Example
a = [3, 1, 2]
a.append(4); a.extend([5, 6]); a.insert(0, 9)
print(a, a.pop(), a.index(1))
a.sort(reverse=True)
print(a, sorted([2, 1]))

Result

[9, 3, 1, 2, 4, 5] 6 2
[9, 5, 4, 3, 2, 1] [1, 2]

Exercise

Add one item.

a.(4)

Quiz Test

Which returns a new sorted list?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.