Python append() and extend() Example

31-Aug-2021

.

Admin

Hi Guys,

In this blog, I will show you python append and extend method in python. We will talk about append() and extend() using python. If you want to append in array using append and extend method in python.

Python adds its argument as a single element to the end of a list. The length of the list increases by one.

Here i will give you four example python append() and extend() example. So let's see the bellow example:

Example 1


my_list = ['a', 'b']

my_list.append('c')

print my_list

Output:

['a','b','c']

Example 2

my_list = ['a', 'b', 'c']

another_list = [1,2,3]

my_list.append(another_list)

print my_list

Output:

['a','b','c',1,2,3]

Example 3

my_list = ['a', 'b', 'c']

another_list = [1,2,3]

my_list.extend(another_list)

print my_list

Output:

['a','b','c',1,2,3]

Example 4

my_list = ['a', 'b']

my_list.extend('c')

print my_list

Output:

['a','b','c']

It will help you....

#Python