List Method in Python
Most Important List Methods for Interviews Method Purpose append(x) Add one item at the end extend(iterable) Add multiple items insert(i, x) Insert at a specific position remove(x) Remove first matching value pop([i]) Remove and return an item (last by default) clear() Remove all items index(x) Find the position of an item count(x) Count occurrences of an item sort() Sort the list reverse() Reverse the list in place copy() Create a shallow copy len(list) Get the number of elements in Check if an element exists In Python slicing , a double colon ( :: ) is used to specify the step (or stride) . start → Starting index (inclusive) end → Ending index (exclusive) step → How many positions to move each time list[start : end : step] numbers = [10, 20, 30, 40, 50, 60, 70] Index: 0 1 2 3 4 5 6 Value: 10 20 30 40 50 60 70 1. [:] → Copy ...