Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

Python List insert(): Adding an Item to a Specific Position

  • 16 Jul, 2025
  • Com 0
List.insert() Method in Python

The list.insert() method inserts a specific element at the specified index in Python.

Python List insert()

The list append() method adds elements to the end of the list, whereas the insert() method allows us to add elements anywhere in the list, providing complete control over the insertion process.

The insert() method does not return a new list; instead, it modifies the existing list.

When it comes to inserting, it is not limited to just integer types; it can insert any data type, including complex objects such as lists or dictionaries.

Syntax

list.insert(index, element)

Parameters

Argument Description
index(required) It is a position in a list where an item is to be inserted. 

If it is a negative number, it will start from the back.

element(required) It is an input object to insert (any type: int, str, list, etc.).

Basic insertion

Let’s define a simple list and insert a new element at index 2. In a list, the index starts with 0.

shares = ['KEI', 'Polycab', 'RR Kabel']

shares.insert(2, 'Delton')  # Inserts at index 2

print(shares)  

# Output: ['KEI', 'Polycab', 'Delton', 'RR Kabel']

Adding at the start

Adding an element at the start of the list using list.insert() method in Python

If you pass position 0, it will start inserting the element at the start of the list.

shares = ['KEI', 'Polycab', 'RR Kabel']

shares.insert(0, 'Delton')  # Inserts at index 0

print(shares)

# Output: ['Delton', 'KEI', 'Polycab', 'RR Kabel']

Adding at the end (index = len(list))

Adding an element at the end of the list using list.insert() method in Python

If you want to add an element at the end, we need to pass the index = len(list). It works similarly to the append() method.

shares = ['KEI', 'Polycab', 'RR Kabel']

shares.insert(len(shares), 'Delton')  # Inserts at the end of the list

print(shares)

# Output: ['KEI', 'Polycab', 'RR Kabel', 'Delton']

Negative indices

Let’s add an element at the second-to-last element by passing the negative index.

shares = ['KEI', 'Polycab', 'RR Kabel']

shares.insert(-2, 'Delton')  # Inserts at index -2

print(shares)

# Output: ['KEI', 'Delton', 'Polycab', 'RR Kabel']

Out-of-Bounds index handling

What if the index > len(list) or index < -len(list)? How will it handle?

If the index is less than 0, it will append an element at the start of the list.

shares = ['KEI', 'Polycab', 'RR Kabel']

shares.insert(-90, 'Delton')

print(shares)

# Output: ['Delton', 'KEI', 'Polycab', 'RR Kabel']

If the index is greater than the length of the list, it will append the element at the end of the list.

shares = ['KEI', 'Polycab', 'RR Kabel']

shares.insert(90, 'Delton')

print(shares)

# Output:  ['KEI', 'Polycab', 'RR Kabel', 'Delton']

Empty list

What if the input list is empty? Well, it will add the element at index 0.

empty_list = []

empty_list.insert(0, "Polycab")

print(empty_list)

# Output: ['Polycab']

Comparison with append() and extend()

Here is the program to differentiates between insert(), append(), and extend() methods:

nums = [1, 2, 3]

nums.append(4)
# Output: [1, 2, 3, 4]

nums.insert(0, 0)
# Output: [0, 1, 2, 3, 4]

nums.extend([5, 6])
# Output: [0, 1, 2, 3, 4, 5, 6]

Inserting a Tuple (as an Element) into the List

Let’s add a tuple as a single list element to a list.

Inserting a Tuple (as an Element) into the List

GoT1_list = ['Daenerys', 'Jon', 'Tyrion']

Friends1_tuple = ('Rachel', 'Monica', 'Phoebe')

GoT1_list.insert(2, Friends1_tuple)

print(GoT1_list)

# Output: ['Daenerys', 'Jon', ('Rachel', 'Monica', 'Phoebe'), 'Tyrion']

That’s it!

Post Views: 33
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Convert an Image to Grayscale with Python
Python List append(): Adding an Element to a List

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend