Python List insert(i,x) MethodPython insert() method inserts the element at the specified index in the list. The first argument is the index of the element before which to insert the element. SignatureParametersi : index at which element would be inserted. x : element to be inserted. ReturnIt does not return any value rather modifies the list. Let's see some examples of insert() method to understand it's functionality. Python List insert() Method Example 1Let's see an example to insert an element at 3 index of the list. Output: 1 2 3 After extending: 1 2 3 4 Python List insert() Method Example : listIt is possible to insert a list as an element to the list. See the example where a list is inserted at specified index. Output: 1 2 3 After inserting: 1 2 3 ['4', '5', '6'] Python List insert() Method Example : TupleIt is possible to insert a tuple as an element to the list. See the example where a tuple is inserted at specified index. Output: 1 2 3 After inserting: 1 2 3 ('4', '5', '6') Python List insert() Method Example : SetIt is possible to insert a set as an element to the list. See the example where a set is inserted at specified index. Output: 1 2 3 After inserting: 1 2 3 {'4', '5', '6'} Next TopicC++ Algorithm max() Function |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India