What is the difference between append() and extend() in lists?
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.
Latest Post: What Are the Must-Learn Cyber Security Skills for 2025? Our newest member: marynita Recent Posts Unread Posts Tags
Forum Icons: Forum contains no unread posts Forum contains unread posts
Topic Icons: Not Replied Replied Active Hot Sticky Unapproved Solved Private Closed