In Python, lists are dynamic. You can easily add new items at the end, at a specific position, or by merging with other iterables like lists and tuples.
append() adds a single item to the end of the list.insert() adds an item at a specific index.extend() adds all items from another iterable (list, tuple, set, etc.).append() and insert() add one item at a time.extend() is used to combine sequences or add multiple items at once.None).Use append(item) to add an item at the end of a list.
append() Example
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits) # ['apple', 'banana', 'cherry']
Use insert(index, item) to add an element at a specific index.
insert() Example
fruits = ["apple", "banana", "cherry"]
fruits.insert(1, "orange")
print(fruits) # ['apple', 'orange', 'banana', 'cherry']
Use extend(iterable) to add all items from another list.
extend() with List Example
fruits = ["apple", "banana"]
tropical = ["mango", "pineapple"]
fruits.extend(tropical)
print(fruits) # ['apple', 'banana', 'mango', 'pineapple']
extend() also works with tuples, sets, or any other iterable, not just lists.
extend() with Tuple Example
fruits = ["apple", "banana"]
fruits.extend(("kiwi", "melon"))
print(fruits) # ['apple', 'banana', 'kiwi', 'melon']
append("cherry") on ["apple", "banana"], the list becomes ['apple', 'banana', 'cherry'].insert(1, "orange") places "orange" at index 1 and shifts existing items to the right, so you get ['apple', 'orange', 'banana', 'cherry'].extend(tropical) with tropical = ["mango", "pineapple"] adds each item individually, giving ['apple', 'banana', 'mango', 'pineapple'].("kiwi", "melon") works the same way and produces ['apple', 'banana', 'kiwi', 'melon'].fruits list directly, so no new list is created.append() for adding single items to the end of a list.extend() when combining two sequences or adding multiple items at once.insert() when you need to place an item in the middle or at a specific index.insert() shifts existing elements to the right, which can be slower on large lists.fruits.append(["mango", "pineapple"]), the entire list becomes a single nested item, not merged. Use extend() to avoid nesting.extend() requires an iterable. Using a non-iterable like fruits.extend(5) will raise a TypeError.extend() instead of many insert() calls at the front.append()."grape" at the start of a fruit list using insert().extend() and print the result.("red", "green", "blue").append() vs extend() using another list and observe the difference in the final list structure.append, insert, extend) at least once.