Differentiate between append ()and extend()method of list
Answers
Answered by
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
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
Physics,
3 months ago
History,
3 months ago
Physics,
3 months ago
Math,
7 months ago
World Languages,
11 months ago