ScanSkill

extend

extend() function or method is used in python list to extend the list by appending all the items from the iterable.

Syntax

list.extend(iterable)

Here,

  • iterable: Required. Any iterable type (list, set, tuple, etc.)

Examples

>>> list1 = [1, 2]
>>> list1.extend([3, 4])
>>> list1
[1, 2, 3, 4]
  • With String type
>>> list1 = [1, 2, 3, 4]
>>> list1.extend('cloudy')
>>> list1
[1, 2, 3, 4, 'c', 'l', 'o', 'u', 'd', 'y']
  • With dict type
>>> list1 = [1, 2, 3, 4, 'c', 'l']
>>> list1.extend({'x': 100, 'y': 200})
>>> list1
[1, 2, 3, 4, 'c', 'l', 'x', 'y']

See also

append() and insert()