Course
Remove Array Items
Python Tutorial
This Python tutorial has been written for the beginners to help them understand the basic to advanced concepts of Python Programming Language. After completing this tutorial, you will find yourself at a great level of expertise in Python, from where you can take yourself to the next levels to become a world class Software Engineer.
Remove Array Items
The array class defines two methods with the help of which we can remove an element from the array. It has
remove()
and pop()
methodsarray.remove() Method
The
remove()
method removes the first occurrence of a given value from the arraySyntax
array.remove(v)
Parameters
- v − The value to be removed from the array
Example
import array as arra = arr.array('i', [1, 2, 1, 4, 2])a.remove(2)print (a)
It will produce the following output
array('i', [1, 1, 4, 2])
array.pop() Method
The
pop()
method removes an element at the specified index from the array, and returns the removed element.Syntax
array.pop(i)
Parameters
- i − The index for the eminent to be removed. The method returns element at ith position after removal.
Example
import array as arra = arr.array('i', [1, 2, 1, 4, 2])a.pop(2)print (a)
It will produce the following output
array('i', [1, 2, 4, 2])
Practice with Online Editor
Note: This Python online Editor is a Python interpreter written in Rust, RustPython may not fully support all Python standard libraries and third-party libraries yet.
Remember to save code(Ctrl
+S
Or
Command
+S
) before run it.