Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What is the difference between "Extend" and "Append" in Python 3

–2 votes
asked Aug 27, 2020 by Abdallah Abdel-Ghani (160 points)
reshown Aug 31, 2020 by Abdallah Abdel-Ghani

2 Answers

+1 vote
answered Aug 28, 2020 by Peter Minarik (84,720 points)
selected Aug 30, 2020 by Abdallah Abdel-Ghani
 
Best answer

Please, see the following documentation:

The main difference is that append adds only one item to the end of the list, while extend adds any iterable, which could be a single element or another list, etc.

In other words, if you want to add only one item to a list (in a single instruction), you can use either of them, but if you want to add multiple, only extend() will work.

commented Aug 30, 2020 by Abdallah Abdel-Ghani (160 points)
Thank you very much!!!
0 votes
answered Aug 28, 2020 by 64 MOSIKAN M (140 points)

append() method adds an element to a list whereas extend() method concatenates the first list with another list.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...