Python List extend() Method

Python List extend() Method

Now, we are going to learn about the extend method. As the name of the method suggests, with the extend method, we can append all the items from the iterable to the list. So, Let’s have a look at a simple program, which demonstrates the same thing.

Python List extend() Method

As you can see in the above program, we have two lists here, list1 and list2, and then we are calling the extend method, and we are passing another list to the extend method. As a result, we can simply say that the list with the reference variable list1 would be extended, by appending all the items from the specified iterable (list in our case). If you try to execute the program and observe the output, you will find that the list1 that we are printing now, is extended.

You can try using the extend method for some other iterables, like string, tuple, etc. As and when required, we can make use of the extend method in our programs. Remember that with the extend method, the list gets extended, by appending all the items from the specified iterable to the list.