Computer Science

Differentiate between append() and extend() methods and provide examples of each.

Python List Manipulation

1 Like

Answer

append() methodextend() method
The append() method adds a single item to the end of the list. The single element can be list, number, strings, dictionary etc.The extend() method adds one list at the end of another list.
The syntax is list.append(item).The syntax is list.extend(list1).
For example,
list1 = [1, 2, 3]
list1.append(4)
print(list1)
For example,
list1 = [1, 2, 3]
list1.extend([4, 5])
print(list1)

Answered By

3 Likes


Related Questions