append()Īppends a single element to the end of the list. The following table shows the differences between extend() and append() in Python lists. The extend() method extends the list by appending all the elements of the iterable object as individual elements of the list. ![]() The syntax of extend() method is: list.extend(element) The extend() is also a python list method that adds an element to the end of a list but it adds the element by extending the iterable object and not as a single element. You can see in the output above appended list is added as a single element of the list the same for the tuple. a = Īppending a collection of items: a = ![]() The append() method adds the entire element as it is, making it a single element of the list. The syntax of append() method is: list.append(element) The append() is a python list method that adds an element to the end of a list. In this short guide, we will discuss the differences between the extend and append in Python lists with examples.īoth extend and append are used to add elements to a list in Python but they have different uses.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |