CBSE Class 11 Computer Science Question 52 of 82

Lists in Python — Question 17

Back to all questions
17
Question

Question 12

Differentiate between append() and extend() methods of list.

Answer
append()extend()
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 of append() method is list.append(item).The syntax of extend() method is list.extend(list1).
For example:
lst1 = [10, 12, 14]
lst1.append(16)
print(lst1)
Output — [10, 12, 14, 16]
For example:
t1 = ['a', 'b', 'c']
t2 = ['d', 'e']
t1.extend(t2)
print(t1)
Output — ['a', 'b', 'c', 'd', 'e']