Login
Remember
Register
Ask a Question
How do you insert an object at a given index in Python?
0
votes
asked
May 10, 2023
in
Python Flask
by
john ganales
How do you insert an object at a given index in Python?
pyhton-index
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
May 10, 2023
by
john ganales
Let’s build a list first.
>>> a=[1,2,4]
Now, we use the method insert. The first argument is the index at which to insert, the second is the value to insert.
>>> a.insert(2,3)
>>> a
[1, 2, 3, 4]
...