Computer Science, asked by akshit1590, 7 months ago

Differentiate between append ()and extend()method of list​

Answers

Answered by Anonymous
9

When append() method adds its argument as a single element to the end of a list, the length of the list itself will increase by one. Whereas extend() method iterates over its argument adding each element to the list, extending the list.

Answered by saidulnayan781
10

Answer:

append: Appends object at the end.

x = [1, 2, 3]

x.append([4, 5])

print (x)

>>> [1, 2, 3, [4, 5]]

extend: Extends list by appending elements from the iterable.

x = [1, 2, 3]

x.extend([4, 5])

print (x)

>>> [1, 2, 3, 4, 5]

Similar questions