list.append() vs list.extend()
list.append() and list.extend() are both Python List Methods APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. list.append(): Appends an item to the end of the list. Modifies the list in place. Its syntax is list.append(x), and it returns none list.extend(): Extends the list by appending all items from the iterable. Its syntax is list.extend(iterable), and it returns none Example of list.append(): lst = [1, 2]
lst.append(3)
# lst = [1, 2, 3]. Example of list.extend(): lst = [1, 2]
lst.extend([3, 4])
# lst = [1, 2, 3, 4]. Read the full references for list.append() and list.extend() to see parameters, edge cases, and example code side by side. Other List Methods APIs worth comparing: list.insert(), list.remove(), list.pop(), list.clear(), list.index(), list.count(). Both belong to the List Methods category in the Python Reference documentation.