Python List insert() MethodPython Functions

Difficulty Level:
Difficulty Level:

The insert() method inserts an element at a specified index in the list.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

list1 = ['MIT', 'CIT', 'Yale','UCI']

list1.insert(1, 'google')

print("the new list: ", list1)

Output:

the new list:  ['MIT', 'google', 'CIT', 'Yale', 'UCI']

Syntax

list.insert(index, element)

Parameters

Name Description
index The position where an element needs to be inserted.
element The element to be inserted in the list.

Return Value

It doesn’t return any value.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us