1. Help Center
  2. Python Programming

how do you differentiate between append() and extend()?

append() adds an element to the end of the list
Example -
>>lst=[1,2,3]
 
>>lst.append(4)
 
>>lst
 
Output:[1,2,3,4]
 
extend() adds elements from an iterable to the end of the list
Example -
>>lst=[1,2,3]
 
>>lst.extend([4,5,6])
 
>>lst
 
Output:[1,2,3,4,5,6]