CBSE Class 11 Computer Science Question 23 of 42

Practice Paper — Question 5

Back to all questions
5
Question

Question 23(a)

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

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)