Python - Print list after removing element at given index Last Updated : 15 Jan, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will explore different ways to remove an element from a list at a given index and print the updated list, offering multiple approaches for achieving this.Using pop()pop() method removes the element at a specified index and returns it. Python li = [10, 20, 30, 40, 50] index = 2 li.pop(index) print(li) Output[10, 20, 40, 50] Explanation:pop() method removes the element at the specified index (2 in this case), which is 30, from the list li.After the pop(), the list li is updated to [10, 20, 40, 50], with the element at index 2 removed. Using List SlicingWe can use list slicing to remove an element by excluding the element at the given index. Python li = [10, 20, 30, 40, 50] index = 2 li = li[:index] + li[index+1:] print(li) Output[10, 20, 40, 50] Explanation:This code creates a new list by concatenating two slices of the original list l: one from the beginning up to index (excluding the element at index), and the other from index+1 to the end of the list.As a result, the element at index 2 (which is 30) is removed, and the updated list is [10, 20, 40, 50]. Using del Keyworddel keyword can be used to delete an element at a specific index. Python li = [10, 20, 30, 40, 50] index = 2 del li[index] print(li) Output[10, 20, 40, 50] Explanation:del statement removes the element at the specified index (2 in this case), which is 30, from the list li.After using del, the list li is updated to [10, 20, 40, 50], with the element at index 2 removed.Using List ComprehensionList comprehension can be used to create a new list excluding the element at the specified index. Python l = [10, 20, 30, 40, 50] index = 2 l = [l[i] for i in range(len(l)) if i != index] print(l) Output[10, 20, 40, 50] Explanation:This code uses list comprehension to create a new list by iterating over the indices of the original list li and including only those elements where the index is not equal to 2.As a result, the element at index 2 (which is 30) is excluded, and the updated list is [10, 20, 40, 50]. Comment More infoAdvertise with us Next Article Python - Print list after removing element at given index S Striver Follow Improve Article Tags : Misc Python python-list Python list-programs Practice Tags : Miscpythonpython-list Similar Reads Remove Last Element from List in Python Given a list, the task is to remove the last element present in the list. For Example, given a input list [1, 2, 3, 4, 5] then output should be [1, 2, 3, 4]. Different methods to remove last element from a list in python are:Using pop() methodUsing Slicing TechniqueUsing del OperatorUsing Unpacking 2 min read Remove first element from list in Python The task of removing the first element from a list in Python involves modifying the original list by either deleting, popping, or slicing the first element. Each method provides a different approach to achieving this. For example, given a list a = [1, 2, 3, 4], removing the first element results in 2 min read Ways to remove particular List element in Python There are times when we need to remove specific elements from a list, whether itâs filtering out unwanted data, deleting items by their value or index or cleaning up lists based on conditions. In this article, weâll explore different methods to remove elements from a list.Using List ComprehensionLis 2 min read Remove all the occurrences of an element from a list in Python The task is to perform the operation of removing all the occurrences of a given item/element present in a list. Example Input1: 1 1 2 3 4 5 1 2 1 Output1: 2 3 4 5 2 Explanation : The input list is [1, 1, 2, 3, 4, 5, 1, 2] and the item to be removed is 1. After removing the item, the output list is [ 4 min read Difference Between Del, Remove and Pop in Python Lists del is a keyword and remove(), and pop() are in-built methods in Python. The purpose of these three is the same but the behavior is different. remove() method deletes values or objects from the list using value and del and pop() deletes values or objects from the list using an index.del Statementdel 2 min read Python | Remove and print every third from list until it becomes empty Given a list of numbers, Your task is to remove and print every third number from a list of numbers until the list becomes empty. Examples: Input : [10, 20, 30, 40, 50, 60, 70, 80, 90] Output : 30 60 90 40 80 50 20 70 10 Explanation: The first third element encountered is 30, after 30 we start the c 4 min read How to Remove Item from a List in Python Lists in Python have various built-in methods to remove items such as remove, pop, del and clear methods. Removing elements from a list can be done in various ways depending on whether we want to remove based on the value of the element or index.The simplest way to remove an element from a list by i 3 min read How to Get First N Items from a List in Python Accessing elements in a list has many types and variations. This article discusses ways to fetch the first N elements of the list.Using List Slicing to Get First N Items from a Python ListThis problem can be performed in 1 line rather than using a loop using the list-slicing functionality provided b 4 min read Get index in the list of objects by attribute in Python In this article, we'll look at how to find the index of an item in a list using an attribute in Python. We'll use the enumerate function to do this. The enumerate() function produces a counter that counts how many times a loop has been iterated. We don't need to import additional libraries to utili 2 min read Like