Skip to content
Justice Tech School

List Methods

append adds to the end, insert adds at a position, remove deletes a value, pop removes by position (and returns the item), index finds a position, count counts matches and clear empties the list. len gives the size, and in checks membership.

Example
fruits = ["apple", "banana"]
fruits.append("cherry")
fruits.insert(1, "mango")
print(fruits)
fruits.remove("banana")
print(fruits.pop())
print(fruits)
print(fruits.index("mango"), len(fruits), "apple" in fruits)

Result

['apple', 'mango', 'banana', 'cherry']
cherry
['apple', 'mango']
1 2 True

Exercise

Add an item to the end.

items.("x")

Quiz Test

What does pop() do?

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