Python List append()

The append() method is used to add a single item to the end of a list.

Syntax

list.append(item)

Parameter

item: The element you want to add to the list. It can be any Python object (number, string, another list, etc.).

Example: Add an item to the list

my_list = [11, 22, 33]

my_list.append(44)
print(my_list) # Output: [11, 22, 33, 44]

Key Points to Remember

(1) The append() method modifies the original list.

(2) You can append different types of objects, such as numbers, strings, other lists, tuples, dictionaries, or even custom objects to the list.

(3) You can only append one item at a time. If you want to add multiple items to the list, you can use the extend() method.

Appending a list to another list

The append() method adds the entire list as a single element to the end of the other list, which creates a nested list.

list1 = [1, 2, 3]
list2 = [4, 5, 6]

list1.append(list2)
print(list1) # Output: [1, 2, 3, [4, 5, 6]]

If you want to add the elements of one list to another, instead of creating a nested list, you should use the extend() method or the + operator.