w3resource

Python: Remove a specified item using the index from an array


11. Remove a Specified Item Using the Index of an Array

Write a Python program to remove a specified item using the index of an array.

Pictorial Presentation:

Python Exercises: Remove a specified item using the index from an array

Sample Solution:

Python Code :

from array import *
array_num = array('i', [1, 3, 5, 7, 9])
print("Original array: "+str(array_num))
print("Remove the third item form the array:")
array_num.pop(2)
print("New array: "+str(array_num))

Sample Output:

Original array: array('i', [1, 3, 5, 7, 9])                            
Remove the third item form the array:                                  
New array: array('i', [1, 3, 7, 9])

For more Practice: Solve these Related Problems:

  • Write a Python program to remove the element at a given index from an array using the pop() method.
  • Write a Python program to delete an element by index from an array using the del statement and then print the array.
  • Write a Python program to implement a function that removes an element at a specified index and returns the modified array.
  • Write a Python program to compare the results of using pop() and slicing to remove an element from an array.

Go to:


Previous: Write a Python program to insert a new item before the second element in an existing array.
Next: Write a Python program to remove the first occurrence of a specified element from an array.

Python Code Editor:

Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.