Latest web development tutorials

Python3 List extend () method

Python3 list Python3 list


description

extend () function is used at the end of the list of additional disposable another sequence of a plurality of values ​​(extended the original list with a new list).

grammar

extend () method syntax:

list.extend(seq)

parameter

  • seq - list element.

return value

This method does not return a value, but will add a list of new content in the existing list.

Examples

The following example shows the extend () method using the function:

#!/usr/bin/python3

list1 = ['Google', 'w3big', 'Taobao']
list2=list(range(5)) # 创建 0-4 的列表
list1.extend(list2)  # 扩展列表
print ("扩展后的列表:", list1)

Examples of the above output results are as follows:

扩展后的列表: ['Google', 'w3big', 'Taobao', 0, 1, 2, 3, 4]

Python3 list Python3 list