1 Answers
Python List Methods: append() vs extend()
In Python, the append() method is used to add a single element to the end of a list, while the extend() method is used to add multiple elements to the end of a list.
Key Differences:
- append(): Appends an element as a single object to the list.
- extend(): Appends elements from an iterable (such as a list, tuple, or string) to the list.
It is important to note that while append() adds the specified element as a single object, extend() iterates over the elements in the iterable and adds them individually to the list.
Choose extend() when you want to add multiple elements and append() when you want to add a single element to the list.
Please login or Register to submit your answer