-extend() is a python in-build function which is used to add some sequence to the list.
- It extend the list
-It take one argument which is some kind of sequence like list,tuple and set.
Syntax-
list.extend(seq)
Example
list is [1,2,3]
then list.extend([4,5]) will give the [1,2,3,4,5]
list is [1,2,3]
list.extend("Hii") will give [1,2,3,'H','i','i']
program-
l=[5,2,3,7,1]
l.extend([3,4,5])
print(l)
l.extend((1,2,"Hii"))
print(l)
l.extend(("Hello",2,3))
print(l)
l.extend(["string","string"])
print(l)
l.extend("World")
print(l)
[5, 2, 3, 7, 1, 3, 4, 5]
[5, 2, 3, 7, 1, 3, 4, 5, 1, 2, 'Hii']
[5, 2, 3, 7, 1, 3, 4, 5, 1, 2, 'Hii', 'Hello', 2, 3]
[5, 2, 3, 7, 1, 3, 4, 5, 1, 2, 'Hii', 'Hello', 2, 3, 'string', 'string']
[5, 2, 3, 7, 1, 3, 4, 5, 1, 2, 'Hii', 'Hello', 2, 3, 'string', 'string', 'W', 'o', 'r', 'l', 'd']