saving . . . saved How to add elements at different positions? has been deleted. How to add elements at different positions? has been hidden .
How to add elements at different positions?
Title
Question
By using append function we can add element at last position but how can we add elements at different positions rather than last position

Python-3.4.3 Getting-started-with-Lists 07-08 min 10-20 sec 01-06-20, 9:46 a.m. Chasta

Answers:

You can use the list.insert(position, element) method
For example
l = [1, 2, 4]
If I want to add an element after 2 then the insert command is
l.insert(2, 3)
new list becomes
l = [1, 2, 3, 4]
01-06-20, 9:55 a.m. aditya94palaparthy@gmail.com
Thanks
01-06-20, 9:57 a.m. Chasta

Login to add comment


Log-in to answer to this question.