Python provides built-in methods to append or add elements to the list. We can also append a list into another list. These methods are given below.
- append(elmt) - It appends the value at the end of the list.
- insert(index, elmt) - It inserts the value at the specified index position.
- extends(iterable) - It extends the list by adding the iterable object.
1. append(elmt)
This function is used to add the element at the end of the list. The example is given below.
Example -
Output:
2. insert(index, elmt)
The insert() function adds the elements at the given an index position. It is beneficial when we want to insert element at a specific position. The example is given below.
Example -
Output:
3. extend(iterable)
The extends() function is used to add the iterable elements to the list. It accepts iterable object as an argument. Below is the example of adding iterable element.
Example -
Output: