+ 1
What is extend() function in python?
See I know the difference in both append() and extend() function but, I'm confused in extend() function as I'm finding it similar to append...can u tell the example of extend(). Please don't share code just tell me the small example.
3 Answers
+ 6
a=[1,2,3]
a.append([4,5])
print(a)
[1,2,3,[4,5]]
a.extend([5,6])
print(a)
[1,2,3,[4,5],5,6]
+ 3
Append appends a single item.
So if you append a list, it will be in there as a whole.
Extend takes an iterable (list, tuple, str whatever) and inserts the elements one by one!
+ 2
Thanks u all