How do you insert an object at a given index in Python?

Hi, I want to know how do you insert an object at a given index in Python.

2 Likes

If you want to insert an object at a specified index, you’d create a list

>>> L1=[w,x,z]

You’ll have to use the method insert. Here, the first argument is the index where you have to inert and the second argument is the value that you want to insert.

>>> L1.insert(2,y)

Hope it would help.

3 Likes