Method Name:
insert
Method Signature:
insert(indexBefore, newElement)
Method Overview:
-
The insert method adds a new element to the list.
-
The new element is added to the list before the specified index.
Parameters:
indexBefore - The index before which the new element is to be added.
newElement - The new element that is to be added to the list.
Return Value:
None
Example:
# Example Python program that creates a list and inserts elements to it # Create a list # Insert an element at the beginning of the list # Insert an element at the end of the list # Insert an element at the end of the list # Insert an element at a specified index print(langs); |
Output:
['Fortran', 'COBOL', 'Pascal', 'C++', 'Python', 'Java'] |