H2K Infosys Forum

What is the differe...
 
Notifications
Clear all

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

 
Member Moderator

In Python, the difference between append() and extend() is essential to understand, especially for beginners taking a python programming training course:

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

  • extend() adds each element of an iterable individually into the list.

Example:

 
a = [1, 2]
a.append([3, 4]) # ➝ [1, 2, [3, 4]]

a.extend([3, 4]) # ➝ [1, 2, 3, 4]

This is a common interview question and a core concept taught in every good python programming training course because it helps learners understand list behavior and data manipulation more effectively.


Quote
Topic starter Posted : 13/11/2025 11:30 am
Share: