Explore Topics

How To Insert Item Into An Specific Index In A List?

Last Updated : 18 Apr, 2025 - Asked By Ashok

Here is a list in Python,

    list = ["Red", "Blue", "Green", "White","Yellow"]

I want to Insert "Gray" into the second index of list. How to do this in Python?

python  insert into list 

Answers
2024-10-02 12:03:13

To insert the specific value in a list, refer to the index of that particular value.

In your case, You have to insert Gray into the second index of the list, which means you have to insert it after "Blue". In the above example, "Red" stands to the 0th index and "Blue" stands to the 1st index. To insert it after the first index,

code will be like this,

               list = ["Red", "Blue", "Green", "White","Yellow"]
               list.insert(2, "gray")
               print(list)

Output:

               ['Red', 'Blue', 'gray', 'Green', 'White', 'Yellow']

Your Answer



Other Resources

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

Q&A Image
Q&A

Ask your coding-related doubts and get answers.

Certification Image
Certification

Earn certifications to enhance your resume.

internships Image
Internships

Hands-on projects to improve your skills.

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

blog Image
Blogs

Add your technical blogs and read technical topics.

Certification Image
Certifications

Earn certifications to enhance your resume.