H2K Infosys Forum

What is the differe...
 
Notifications
Clear all

What is the difference between append() and extend()?

 
Member Moderator

In Python, understanding the difference between append() and extend() is essential—especially when preparing for the Best Python Certification programs, where list operations are frequently tested.

  • append() adds a single element to the end of a list.

  • extend() adds multiple elements from an iterable (list, tuple, set, etc.) to the existing list.

Example:

 
a = [1, 2]
a.append([3, 4]) # Result: [1, 2, [3, 4]]
a.extend([3, 4]) # Result: [1, 2, 3, 4]

Use append() when you want to add one item, and use extend() when you want to merge multiple elements into a list.


Quote
Topic starter Posted : 15/11/2025 4:50 am
Share: