Python List append()


Python List append() method

Python List append() method appends given object to the end of this list.

Python List append()
https://youtu.be/vuckM-Ft96Q?si=hMykkyE6fEGnW7RJ

In this tutorial, you will learn the syntax of, and how to use, List append() method, with examples.

Syntax of List append()

The syntax of List append() method is

list.append(object)

Parameters

append() method can take one parameter. Let us see the parameter, and its description.

ParameterDescription
objectAn item (any valid Python object) to be appended to the list.

Return value

append() method returns None.

Please note that append() method modifies the source list.

Examples

1. Append item 98 to the given list in Python

In the following program, we take a list my_list with values [52, 41, 63]. We have to append an object 98 to this list.

Call append() method on the list my_list and pass the object 98 as argument to the method.

Python Program

my_list = [52, 41, 63]
my_list.append(98)
print(my_list)

Output

[52, 41, 63, 98]

2. Append item 98 to the given list in Python

In the following program, we take a list of strings in my_list with some initial values. We have to append an object 'mango' to this list.

Call append() method on the list my_list and pass the object 'list' as argument to the method.

Python Program

my_list = ['apple', 'banana', 'cherry']
my_list.append('mango')
print(my_list)

Output

['apple', 'banana', 'cherry', 'mango']

The given object is appended to the list.

3. Append items in another list to this list in Python

You can use append() method to append another list of element to this list.

In the following program, we shall use Python For loop to iterate over elements of second list and append each of these elements to the first list.

Python Program

list_1 = [52, 41, 63]
list_2 = [47, 27, 97]

for element in list_2:
    list_1.append(element)

print(list_1)

Output

[52, 41, 63, 47, 27, 97]

Summary

In this tutorial of Python Examples, we learned about List append() method, how to use append() method to append an object to the list, with syntax and examples.