🛠 List Methods
Last Updated: 17th August 2025
In Python, lists come with many built-in methods and we can also use useful functions to work with them easily. Let’s cover them one by one.
- append() – Adds a single element at the end of the list.
fruits = ["apple", "banana"]
fruits.append("mango")
print(fruits) # ['apple', 'banana', 'mango']
- extend() – Adds multiple elements to the end of the list.
fruits = ["apple", "banana"]
fruits.extend(["mango", "kiwi"])
print(fruits) # ['apple', 'banana', 'mango', 'kiwi']
- insert() – Inserts an element at a specific index in the list.
fruits = ["apple", "banana"]
fruits.insert(1, "mango")
print(fruits) # ['apple', 'mango', 'banana']
- remove() – Removes the first occurrence of a specific element from the list.
fruits = ["apple", "banana", "apple"]
fruits.remove("apple")
print(fruits) # ['banana','apple']
- pop() – Removes and returns element at a given index (default last).
fruits = ["apple", "banana", "cherry"]
popped_fruit = fruits.pop(1)
print(fruits) # ['apple', 'cherry']
print(popped_fruit) # 'banana'
- index() – Returns index of first occurrence of element.
fruits = ["apple", "banana", "cherry"]
index = fruits.index("banana")
print(index) # 1
- count() – Returns number of occurrences of element.
fruits = ["apple", "banana", "cherry", "apple"]
count = fruits.count("apple")
print(count) # 2
-- sort() – Sorts list in ascending order (changes original).
nums = [3, 1, 2]
nums.sort()
print(nums) # [1, 2, 3]
- reverse() – Reverses list order (in-place).
nums = [1, 2, 3]
nums.reverse()
print(nums) # [3, 2, 1]
- copy() – Returns a shallow copy of the list.
fruits = ["apple", "banana", "cherry"]
new_fruits = fruits.copy()
print(new_fruits) # ['apple', 'banana', 'cherry']
- clear() – Removes all elements from the list.
fruits = ["apple", "banana", "cherry"]
fruits.clear()
print(fruits) # []