list.insert()
list.insert() is a Python method in the List Methods category. Inserts an item at a given position. The first argument is the index. The syntax is list.insert(index, x). Parameters: index — position to insert at. Returns: None. A typical example: lst = [1, 3]
lst.insert(1, 2)
# lst = [1, 2, 3]. A close sibling is list.append(), which appends an item to the end of the list. Modifies the list in place. A close sibling is list.extend(), which extends the list by appending all items from the iterable. A close sibling is list.remove(), which removes the first occurrence of x from the list. Raises ValueError if not found. A close sibling is list.pop(), which removes and returns the item at the given position (last by default). More about this category: List methods for sequence manipulation — append, sort, pop, extend, and more. For a broader walkthrough, read the List Methods guide.