Python List extend() Method

Python 列表Python Lists


Description

The extend() function is used to append multiple values from another sequence at the end of a list (extending the original list with a new list).

Syntax

The syntax of the extend() method is:

list.extend(seq)

Parameters

  • seq -- List of elements.

Return Value

This method has no return value, but it adds new list contents to the existing list.

Example

The following example demonstrates how to use the extend() function:

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc', 123];
bList = [2009, 'manni'];
aList.extend(bList)

print "Extended List : ", aList ;

The output of the above example is as follows:

Extended List :  [123, 'xyz', 'zara', 'abc', 123, 2009, 'manni']

Python 列表Python Lists

Other Extensions