all I am learning python from some days back, and please help me to How to Write a Python program to insert a new item before the second element in an existing array
Asked
Active
Viewed 830 times
1 Answers
0
The python list data structure has a insert method associated with it..
The insert method takes two arguments position, value-to-insert.
So for your case it will be something like this.
In [1]: l1 = ['a','b','c','d']
In [2]: l1.insert(1,'x')
In [3]: l1
Out[3]: ['a', 'x', 'b', 'c', 'd']
In [4]:
We are inserting at index 1, because list index starts with 0.

Arun Kaliraja Baskaran
- 1,046
- 7
- 14
-
1Thanks, Arun for the reply I found this https://www.techgeekbuzz.com/python-arrays/ on the internet, the author describes the python array very well. – lokeshjoshi Feb 14 '21 at 13:26