Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Remove Last Element from List in Python
Next article icon

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 Slicing

We 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 Keyword

del 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 Comprehension

List 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].


Next Article
Remove Last Element from List in Python

S

Striver
Improve
Article Tags :
  • Python
  • Python list-programs
  • python-list
Practice Tags :
  • python
  • python-list

Similar Reads

  • Index of Non-Zero Elements in Python list
    We are given a list we need to find all indexes of Non-Zero elements. For example, a = [0, 3, 0, 5, 8, 0, 2] we need to return all indexes of non-zero elements so that output should be [1, 3, 4, 6]. Using List ComprehensionList comprehension can be used to find the indices of non-zero elements by it
    2 min read
  • 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 ComprehensionLi
    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
  • Get Index of Multiple List Elements in Python
    In Python, retrieving the indices of specific elements in a list is a common task that programmers often encounter. There are several methods to achieve this, each with its own advantages and use cases. In this article, we will explore some different approaches to get the index of multiple list elem
    3 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 Statementde
    2 min read
  • Python - Append List every Nth index
    Given 2 list, append list to the original list every nth index. Input : test_list = [3, 7, 8, 2, 1, 5, 8], app_list = ['G', 'F', 'G'], N = 3 Output : ['G', 'F', 'G', 3, 7, 8, 'G', 'F', 'G', 2, 1, 5, 'G', 'F', 'G', 8] Explanation : List is added after every 3rd element.Input : test_list = [3, 7, 8, 2
    5 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
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences